How To Enable Shortlinks In WordPress

How To Enable Shortlinks In WordPress

Have you ever felt the need to enable shortlinks in WordPress? If yes, this short article will help you solve the issue.

Generally, while sharing any blog post on social media, the platform limits the number of characters in the URL and that is why we need to use the shortlinks.

There are two ways to get the shortlink in WordPress:

  1. Using custom code
  2. Using a URL shortener plugin

Both methods are easy.

Just in case, you need to handle many short links for affiliate purposes, it’s better to use a plugin so can track the performance of these links.

Enable shortlinks in WordPress using custom code

By default, WordPress hides the shortlink button.

You can easily enable the “Get Shortlink” button by using the below code snippet.

Add the code in the functions.php file of your child theme.

Note: Always make sure to take a backup of the website.

add_filter( 'get_shortlink', function( $shortlink ) {
return $shortlink;

That’s it!

In case you need to change the domain name in the URL shortener, you need to replace the domain name in the function.

Check the below code:

add_filter( 'get_shortlink', 'change_get_shortlink' );
function change_get_shortlink( $shortlink ) {
    return str_replace( '', '', $shortlink );

Get shortlinks using a plugin.

In case, you’re uncomfortable with the code and prefer using a URL Shortener plugin then try using the Prettylinks plugin.

Follow the steps to get short links for your posts and pages:

  1. Activate the Pretty links plugin
  2. Check the Pretty links section in your WordPress dashboard.
  3. Enter the URL in the target URL input field. The plugin will create a short URL that you can now use for sharing.

That’s it! You have enabled shortlinks in WordPress.

Now you can use these links in social sharing platforms to drive more traffic to your website.

Hope you enjoyed the post. Keep sharing!

Recommended reading:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top