homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / WordPress
Forum Library, Charter, Moderators: lorax & rogerd

WordPress Forum

Remove wordpress shortlink header element without core changes

 7:28 pm on Jul 13, 2011 (gmt 0)

When a post is published the header element 'Link:' is appended to the header output of your post with the non-permalink shortlink url, if it's not blank. ie: 'Link: <example.com/?p=8695>; rel=shortlink'.

While you can remove this text from the wp_head section of your html output by adding 'remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );' to your functions.php file you CANNOT use a command in functions.php to stop the header output (because headers are sent first).

The function 'wp_shortlink_header' in link-template is the source of the header element 'Link' and commenting out the line starting with 'header' removes the element but that requires changes to core wordpress files that get undone every update.

What would be the most efficient way to remove this header element without core changes?



 7:36 pm on Jul 13, 2011 (gmt 0)

[edit: sorry, didnt read your post properly]


 7:39 pm on Jul 13, 2011 (gmt 0)

P.S. I asked this in another forum and was bombarded with "why" and "don't do that" etc comments but nobody knew how. "It doesn't cause problems and it's on every wordpress site so don't worry about it" isn't helpful.

The reason I need a solution: I'm implementing a shortening service and the 'shortlink' header element needs to point to the right place, it doesn't. I 'could' change how it works but REMOVING it is the solution I want/need. if you have any idea on how to remove the stinking 'Link:' element without a core change, thanks in advance.


 7:43 pm on Jul 13, 2011 (gmt 0)

cant you just override it with your one, after it gets called? just put a function in your functions.php file which repeats the same header with your own value.

i've never actually tried doing that, but it sounds like it should work okay. the whole page is assembled before output with wordpress, so you could even call it right at the end of the footer


 7:46 pm on Jul 13, 2011 (gmt 0)

I can unset header elements via functions.php but this one won't unset.


 7:53 pm on Jul 13, 2011 (gmt 0)

what about using the htaccess file to send the header. doesnt that override stuff sent from a .php file? im not sure how easy it would be for you to get it to send your own value though


 8:03 pm on Jul 13, 2011 (gmt 0)

htaccess is not my strong suit.

this works in functions.php by disabling the get_shortlink function.

add_filter( 'get_shortlink', 'disable_stuff' );
function disable_stuff( $data ) {
return false;

That's going to cause problems with some other plugins however and it's in other core files like edit-form-advanced.php so disabling the entire function is a bit overdone.

JUST the header needs to be removed...


 8:18 pm on Jul 13, 2011 (gmt 0)

you mentioned before that the headers get sent before the functions file is called.

...you can get around that by adding a new level of caching around the entire page.

just add a new
ob_start(); to the very start of the header file
ob_end_flush(); to the very end of the footer file

then you can use the original idea of overriding the header with your own one, which you can call right at the end of the footer before you flush it


 8:54 pm on Jul 13, 2011 (gmt 0)

I would think that you should create a custom template of your own and in that template don't include the head element - write your own. Then go in the WP admin, and for the particular page you don't want the head element to be included on, simply set the template to the name of the custom template you created and loaded on the server.

To learn more go here: [codex.wordpress.org...]


 9:28 pm on Jul 13, 2011 (gmt 0)

It's not the <head> element i'm working on, it's the headers sent with the page, the host and status information etc.

This is the relevant section of the wp_includes/link-template.php core file.

* Send a Link: rel=shortlink header if a shortlink is defined for the current page.
* Attached to the wp action.
* @since 3.0.0
* @uses wp_get_shortlink()
function wp_shortlink_header() {
if ( headers_sent() )

$shortlink = wp_get_shortlink(0, 'query');

if ( empty($shortlink) )

header('Link: <' . $shortlink . '>; rel=shortlink', false);

everyone ends up with a header response that includes a NON pretty permalink url like...
Link: example.com/?p64682; rel=shortlink

Documentation for it can be found here (except nothing exists yet) - [codex.wordpress.org...]


 9:37 pm on Jul 13, 2011 (gmt 0)

So even if you modify the custom template to include a header() function of your own, you're saying that headers have already been sent by that time.


 2:01 pm on Jul 14, 2011 (gmt 0)

I'm saying that I can't unset the header value "Link" and I need to.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / WordPress
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved