Remove rel=shortlink from HTTP header

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

<?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

Leave a Comment