3

HTTP header of posts on my site looks like this:

accept-ranges:bytes
cache-control:public, max-age=0,public,public
content-encoding:gzip
content-length:5369
content-type:text/html; charset=UTF-8
date:Fri, 08 Dec 2017 07:27:40 GMT
expires:Fri, 08 Dec 2017 07:19:33 GMT
link:<https://example.com/?p=5697>; rel=shortlink
server:Apache
status:200
vary:Accept-Encoding

How to remove this line from HTTP header responce:

link:<https://example.com/?p=5697>; rel=shortlink

Please, do not confuse this with <head> </head> section of HTML, I removed it from there already, I would like to remove it from HTTP header response too.

2 Answers 2

14
<?php
add_filter('after_setup_theme', 'remove_redundant_shortlink');

function remove_redundant_shortlink() {
    // remove HTML meta tag
    // <link rel='shortlink' href='http://example.com/?p=25' />
    remove_action('wp_head', 'wp_shortlink_wp_head', 10);

    // remove HTTP header
    // Link: <https://example.com/?p=25>; rel=shortlink
    remove_action( 'template_redirect', 'wp_shortlink_header', 11);
}

Tested in WordPress 4.4 and up to 4.9.1

2
  • It is not working for me, I have first line of code in my functions.php, and it removes shortlink from <head> section, but not from http header. I tried second function too, but nothing I still have shortlink in http header. Thanks anyway. Dec 8, 2017 at 15:33
  • @AdvancedSEO, have a look at fixed code.
    – Max Yudin
    Dec 8, 2017 at 17:51
0

This still works in wordpress 5.8.3 if you put it in your themes functions.php - just remember that this file might alter at upgrade.

Solution is Here

1
  • 3
    You could put it in a child theme or a plugin then - it doesn't have to go in the theme's functions.php.
    – Rup
    Jan 17, 2022 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.