Fancy links are great, but they generate huge URLs. These cause problems when you want to send links to others via email, instant message or Twitter.

I’ll show a solution that doesn’t require any plugin, doesn’t go through an external service and doesn’t create any load on your site.

WordPress has default link aliases to every page

Let’s start with an example. This page talks about using Contact Form 7 multilingual:


Do you think that’s a long URL, check out the Japanese version:


It’s got 306 characters! Doesn’t even fit into two tweets.

But, try these two:

These are actually links to the same pages. There’s no magic here. These are the default-format links to those pages. Every page, post, tag or category can be accessed via its default link as well as its fancy link. It’s built into WordPress and doesn’t rely on anything else.

And, here is the function that produces those links:

function wpml_default_link($anchor){

  $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');

    $link = '<a rel="nofollow" href="' . get_options('home') . '?' . $qv . '">' . $anchor . '</a>';
    $link = '';

  return $link;

What it does is:

  1. Determines what kind of page you’re looking at now.
  2. Constructs the default URL for that type of page. It’s different for pages, posts, tags, categories and archives.
  3. Creates a link to that URL.

Adding short links to your pages

You can copy the function from above and paste it to your functions.php file. This will make it available to all the files in your theme. Then, add it somewhere. I think that the footer is a good place, but you choose for yourself.

For wpml.org, we’ve added it to footer.php, making it look like this:


Now, whenever I want to send someone a link to a page on my site, I just use that URL. When visitors come to that URL, they will be redirected by WordPress to the permalink (the fancy URL).

To include in footer, I added this code:

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

Using WPML? It’s already built in!

WPML includes a set of theme helper functions, stored in a file called docs/theme-integration/wpml-integration.php. Just copy that file to your theme’s directory and include it from functions.php. It will already contain a modified version of that function (which also includes the language path), so you can go ahead and use in your theme.