WordPress wp_shortlink_header() Function

Beginner
6 min read
Updated: Nov 2026
3 examples
Sends a 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.

WordPress
<?php add_action( 'template_redirect', 'wp_shortlink_header', 11, 0 ); ?>
CallWhat 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
WordPress
wp_shortlink_header(): void

Parameters

ParameterDescription
No parametersThis function has no parameters.

Return Value

Return ValueDescription
voidNothing is returned. The header is sent.

WordPress Examples

Three short examples. Each one shows the code and what it prints or does.

Example 1 — See what the header looks like

WordPress sends this for a single post by default. You can check it with curl -I.

WordPress
<?php
// Core already does this for you:
add_action( 'template_redirect', 'wp_shortlink_header', 11, 0 );

How It Works

  1. template_redirect runs before the page is shown.
  2. wp_shortlink_header() asks for the shortlink of the page.
  3. 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.

WordPress
<?php
remove_action( 'template_redirect', 'wp_shortlink_header', 11 );

How It Works

  1. The priority 11 must match the one used by core.
  2. remove_action() unhooks the function.
  3. The page loads as usual, without the header.

Example 3 — Change the shortlink value

Use a filter to send your own short domain.

WordPress
<?php
function ctf_short_domain( $shortlink, $id ) {
  return 'https://exm.pl/' . $id;
}
add_filter( 'get_shortlink', 'ctf_short_domain', 10, 2 );

How It Works

  1. get_shortlink is the filter that builds the value.
  2. Our function returns a short link with the post ID.
  3. wp_shortlink_header() sends that new value.

Frequently Asked Questions

It sends a Link header with rel=shortlink, so tools can find a short URL for the page.
No. WordPress already hooks it on template_redirect.
Use remove_action( 'template_redirect', 'wp_shortlink_header', 11 ) in functions.php.
Not on the page. It is an HTTP header. You can see it in your browser's network tab or with curl -I.
wp_shortlink_header() sends an HTTP header. wp_shortlink_wp_head() prints a link tag in the HTML head.

Next: wp_shortlink_wp_head()

Print a shortlink link tag inside the page head.

wp_shortlink_wp_head() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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