WordPress wp_shortlink_wp_head() Function

Beginner
6 min read
Updated: Nov 2026
3 examples
Prints a tag

Definition

In WordPress, wp_shortlink_wp_head() prints a link tag with rel='shortlink' in the head of your page. The tag holds a short address of the post, such as /?p=42.

WordPress already hooks it to wp_head, so it runs on its own. You will see the tag if you view the page source. Learn it so you know 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( 'wp_head', 'wp_shortlink_wp_head', 10, 0 ); ?>
CallWhat it does
wp_shortlink_wp_head()Print the tag. WordPress already does this.
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10 )Turn the tag off.
wp_get_shortlink()Get the shortlink as a string.

It takes no arguments. It prints the tag only on pages that have a shortlink, such as a single post.

Full declaration
WordPress
wp_shortlink_wp_head(): void

Parameters

ParameterDescription
No parametersThis function has no parameters.

Return Value

Return ValueDescription
voidNothing is returned. The tag is printed in the head.

WordPress Examples

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

Example 1 — See the tag in the page source

WordPress prints this in the head for a single post.

WordPress
<?php
// Core already does this for you:
add_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );

How It Works

  1. wp_head runs inside the head tag.
  2. wp_shortlink_wp_head() gets the shortlink of the post.
  3. It prints it as a link tag.

Example 2 — Turn the tag off

Add this to functions.php to clean up the head.

WordPress
<?php
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10 );

How It Works

  1. The priority 10 must match the one used by core.
  2. remove_action() unhooks the function.
  3. The page head no longer has the shortlink tag.

Example 3 — Show a Copy shortlink box

If you want visitors to use the short address, print it yourself with the returning function.

WordPress
<?php
$short = wp_get_shortlink();
if ( $short ) {
  echo '<input type="text" readonly value="' . esc_attr( $short ) . '">';
}

How It Works

  1. wp_get_shortlink() returns the short address as a string.
  2. We print it in a read-only box.
  3. esc_attr() keeps the value safe.

Frequently Asked Questions

It prints a link tag with rel='shortlink' in the head of the page.
No. WordPress already hooks it to wp_head.
Use remove_action( 'wp_head', 'wp_shortlink_wp_head', 10 ) in functions.php.
A short address of a post, such as /?p=42. It works even if you change the post title.
wp_shortlink_wp_head() prints a tag in the HTML head. wp_shortlink_header() sends an HTTP header.

Back to the Link Functions Index

Browse all 25 WordPress link function guides in one table.

Link Functions Index →

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.

7 people found this page helpful