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.

Leave a comment

Talk to me!

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

Scroll Up
%d bloggers like this: