Home WordPress Links Functions wp_shortlink_wp_head() WordPress wp_shortlink_wp_head() Function 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.
<?php add_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 ); ?> Call What 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 wp_shortlink_wp_head(): void Parameters Parameter Description No parametersThis function has no parameters.
Return Value Return Value Description void Nothing 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.
1. See the tag in the page source 2. Turn the tag off 3. Show a Copy shortlink box Example 1 — See the tag in the page source WordPress prints this in the head for a single post.
<?php
// Core already does this for you:
add_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 ); <link rel='shortlink' href='https://example.com/?p=42' /> How It Works wp_head runs inside the head tag.wp_shortlink_wp_head() gets the shortlink of the post.It prints it as a link tag. Example 2 — Turn the tag off Add this to functions.php to clean up the head.
<?php
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10 ); (The <link rel='shortlink' ... /> tag is no longer in the head.) How It Works The priority 10 must match the one used by core. remove_action() unhooks the function.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.
<?php
$short = wp_get_shortlink();
if ( $short ) {
echo '<input type="text" readonly value="' . esc_attr( $short ) . '">';
} <input type="text" readonly value="https://example.com/?p=42"> How It Works wp_get_shortlink() returns the short address as a string.We print it in a read-only box. esc_attr() keeps the value safe.Frequently Asked Questions What does wp_shortlink_wp_head() do? It prints a link tag with rel='shortlink' in the head of the page.
Do I need to call it myself? No. WordPress already hooks it to wp_head.
How do I remove the shortlink tag? Use remove_action( 'wp_head', 'wp_shortlink_wp_head', 10 ) in functions.php.
What is a shortlink? A short address of a post, such as /?p=42. It works even if you change the post title.
What is the difference from wp_shortlink_header()? 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 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.
7 people found this page helpful
Helpful Share Copy link Suggestion