Skip Navigation

We want our visitors to link to us and share our links with others. However, WordPress often generates very long URLs which are difficult to share. I’ll show you how to produce short and unbreakable URLs.

Have a look at this page:

The URL takes 68 characters.

This is the Chinese translation:

That’s 114 characters. A bit long for Twitter and will likely break in an email.

Sure, you can use one of many URL shortening services, but do you really need that? Do you really need to proxy your visitors through a different domain for something as simple as this?

Have a look at the bottom of every page in You’ll see it saying ‘short link to this page’.

The length of these links is around 22 characters. A bit less than before.

And, when you click on it, you’ll see the default link to that page. It’s not something that we invented. This is how WordPress works. Each page has an ID. When you link to that ID, you link to the page. WordPress will redirect visitors to the current permalink, so they see the nice ‘SEO friendly’ URLs.

To add to your theme, first, create a function that generates these default links. This function checks on what type of content we are and generates the URL for it.

You can copy this entire code and add it to your site’s functions.php.

function wpml_default_link($anchor){
    global $sitepress;
    $qv = false;

        $qv = 'p=' . get_the_ID();
        $qv = 'page_id=' . get_the_ID();
        $tag = &get_term(intval( get_query_var('tag_id') ), 'post_tag', OBJECT, 'display');
        $qv = 'tag=' . $tag->slug;
        $qv = 'cat=' . get_query_var('cat');
        $qv = 'year=' . get_query_var('year');
        $qv = 'm=' . get_query_var('year') . sprintf('%02d', get_query_var('monthnum'));
        $qv = 'm=' . get_query_var('year') . sprintf('%02d', get_query_var('monthnum')) . sprintf('%02d', get_query_var('day'));
        $qv = 's=' . get_query_var('s');
        $qv = get_query_var('taxonomy') . '=' . get_query_var('term');

        $link = '<a rel="nofollow" href="' . $sitepress->language_url($sitepress->get_default_language()) . '?' . $qv . '">' . $anchor . '</a>';
        $link = '';

    return $link;

Next, edit your theme and call this function.

We added it to footer.php:

<?php echo(wpml_default_link(__('Short link to this page','wpml-theme'))); ?>

And, that’s all. Now, every page gets this neat short link and invites people to share it.

Go ahead, try it for yourself.

2 Responses to “Short Links to WordPress Content”

    • The PHP at the body of the post defines language_url. If you’re getting a message about that function missing, it means it’s not pasted correctly to your functions.php file.