Home WordPress Links Functions wp_shortlink_header() Definition In WordPress, wp_shortlink_header() sends a short link in the HTTP headers of a page. The header is named Link and it says rel=shortlink. Visitors do not see it, but tools and browsers can read it.
WordPress already hooks this function for you, on the template_redirect action. So you rarely call it yourself. It is useful to know what it does, and how to turn it off with remove_action() .
Syntax WordPress runs it for you. This is the line in core that does it.
<?php add_action( 'template_redirect', 'wp_shortlink_header', 11, 0 ); ?> Call What it does wp_shortlink_header()Send the shortlink header. WordPress already does this. remove_action( 'template_redirect', 'wp_shortlink_header', 11 )Turn the header off. wp_get_shortlink()Get the shortlink of the page as a string.
It takes no arguments . It sends the header only on pages that have a shortlink, such as a single post, and only if headers were not sent yet.
Full declaration wp_shortlink_header(): void Parameters Parameter Description No parametersThis function has no parameters.
Return Value Return Value Description void Nothing is returned. The header is sent.
WordPress Examples Three short examples. Each one shows the code and what it prints or does.
1. See what the header looks like 2. Turn the header off 3. Change the shortlink value Example 1 — See what the header looks like WordPress sends this for a single post by default. You can check it with curl -I.
<?php
// Core already does this for you:
add_action( 'template_redirect', 'wp_shortlink_header', 11, 0 ); Link: <https://example.com/?p=42>; rel=shortlink How It Works template_redirect runs before the page is shown.wp_shortlink_header() asks for the shortlink of the page.It sends it as an HTTP header. Example 2 — Turn the header off Add this to functions.php if you do not want the header.
<?php
remove_action( 'template_redirect', 'wp_shortlink_header', 11 ); (No "Link: ...; rel=shortlink" header is sent.) How It Works The priority 11 must match the one used by core. remove_action() unhooks the function.The page loads as usual, without the header. Example 3 — Change the shortlink value Use a filter to send your own short domain.
<?php
function ctf_short_domain( $shortlink, $id ) {
return 'https://exm.pl/' . $id;
}
add_filter( 'get_shortlink', 'ctf_short_domain', 10, 2 ); Link: <https://exm.pl/42>; rel=shortlink How It Works get_shortlink is the filter that builds the value.Our function returns a short link with the post ID. wp_shortlink_header() sends that new value.Frequently Asked Questions What does wp_shortlink_header() do? It sends a Link header with rel=shortlink, so tools can find a short URL for the page.
Do I need to call it myself? No. WordPress already hooks it on template_redirect.
How do I remove the shortlink header? Use remove_action( 'template_redirect', 'wp_shortlink_header', 11 ) in functions.php.
Can visitors see the header? Not on the page. It is an HTTP header. You can see it in your browser's network tab or with curl -I.
What is the difference from wp_shortlink_wp_head()? wp_shortlink_header() sends an HTTP header. wp_shortlink_wp_head() prints a link tag in the HTML head.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
18 people found this page helpful
Helpful Share Copy link Suggestion