WordPress function get_the_shortlink

Many WordPress functions have a standard version which outputs the results directly and an additional version prefixed with get_ that returns the output – useful for adding to a string and manipulating before output.

One such exclusion is the_shortlink, which returns a short link to any page or post – there is no get_the_shortlink, so many people have to resort to just outputting the result in a FORM field for people to cut & paste.  However, here is a quick way to add the capability to your blog – simply add the following 5 lines to your theme’s function.php file…

Now you just need to call get_the_shortlink() from within your WordPress loop and it will return the shortlink URL.

Unlike the_shortlink it doesn’t accept any parameters, but this is a quick and simple solution.

Posted by David Artiss

Enterprise Happiness Engineer for the WordPress VIP team at Automattic. Gamer, film lover and general fan of all things Marvel, Star Trek and Star Wars. Failed comedian. Writer for The Big Tech Question. World's Greatest Grandma.

Talk to me!

This site uses Akismet to reduce spam. Learn how your comment data is processed.