How to Remove links to WordPress’ internal ‘shortlink’ URLs

Estimated reading time: 2 min

To remove links to WordPress’ internal ‘shortlink’ URLs, follow these steps:

Method 1: Disable Shortlinks via Functions.php

Go to your WordPress dashboard.

Navigate to Appearance > Theme Editor.

Open the functions.php file of your active theme (preferably a child theme).

Add the following code at the end of the file:

remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
remove_action('template_redirect', 'wp_shortlink_header', 11, 0);

Save the changes.


2: Modify Your Theme’s Header

If your theme explicitly includes shortlinks in the <head>, remove them manually:

  1. Open your theme’s header.php file.
  2. Look for: phpCopyEdit<link rel="shortlink" href="<?php echo wp_get_shortlink(); ?>" />
  3. Delete or comment out this line.

3. Disable Shortlinks via a Plugin

If you prefer not to edit theme files, you can use a plugin like Disable Shortlinks or Remove WordPress Shortlinks. These plugins remove shortlinks automatically.


4. Remove Shortlinks from API Responses

If you also want to remove shortlinks from WordPress’ REST API responses, add this code to functions.php:

add_filter('get_shortlink', '__return_false');

This prevents WordPress from generating shortlinks entirely.


Remove Shortlink from HTTP Headers

5. Remove Shortlink from HTTP Headers

By default, WordPress may include shortlinks in the HTTP headers. To remove them, add this to functions.php:

function remove_shortlink_http_header($headers) {
    unset($headers['X-Shortlink']);
    return $headers;
}
add_filter('wp_headers', 'remove_shortlink_http_header');

6. Verify the Changes of Shortlink

After making these modifications:

  • Check your website source code (Ctrl + U in Chrome) to ensure no <link rel="shortlink"> tag exists.
  • Use browser developer tools (F12 > Network > Headers) to verify shortlinks aren’t in HTTP responses.

These steps ensure WordPress doesn’t generate or expose shortlinks anymore. πŸš€


Discover more from HelpZone

Subscribe to get the latest posts sent to your email.

Want to support us? Let friends in on the secret and share your favorite post!

Photo of author

Flo

How to Remove links to WordPress’ internal ‘shortlink’ URLs

Published

Welcome to HelpZone.blog, your go-to hub for expert insights, practical tips, and in-depth guides across technology, lifestyle, business, entertainment, and more! Our team of passionate writers and industry experts is dedicated to bringing you the latest trends, how-to tutorials, and valuable advice to enhance your daily life. Whether you're exploring WordPress tricks, gaming insights, travel hacks, or investment strategies, HelpZone is here to empower you with knowledge. Stay informed, stay inspired because learning never stops! πŸš€

πŸ‘ Like us on Facebook!

Closing in 10 seconds

Leave a Reply