Post Pic

How to: Get short urls for social bookmarking

When sharing urls on Twitter or other social bookmarking tools, you need short urls. The most common solution is to use an url shortener services. Even if this is a good idea, you can get short urls using only WordPress. How? Just read on.

This hack is very simple. Instead of using permalinks, let's use the post ID to get a shorter url.

Paste the following code on your single.php file:

<?php echo get_bloginfo('url')."/?p=".$post->ID; ?>

It will output an url of this form:

http://www.wprecipes.com/?p=54

And you're reading for twitter sharing!

Thanks to Aytemir for this great idea!

25 Responses

May 01 2009 08:09

This recipe is useful for Twitter, but not for other social media because of SEO

May 01 2009 09:45

Can you show an example? Make a short url for this article…

May 01 2009 12:29

Thanks for the credit.

I think WordPress just might do this automatically in the future, since they’ve now own WP.com also: imagine wp.com/?p=3

It doesn’t get much shorter than that…

May 01 2009 13:37

This tips is interesting but I won’t use it. Why ?
You have short URL, but you can also have it from TinyURL Creator, a firefox’s plugin. You loose reader because this type of URL is not SEO ready. So, I’ll prefer SEO ready URL (like these that you have for wp-recipes) and TinyURL plugin.

Anyway, thanks for this recipes and for you work in general !

May 01 2009 15:58

interesting work around. we use headspace2 and seo slugs plug-ins to derive urls from article titles and shorten by removing words such as “a”, “the” etc.

May 02 2009 00:01

wp.com/3 or wp.com/s/3 is a couple characters shorter – http://5thirtyone.com/s/2075

May 02 2009 03:38

Cool recipe, but how is this different than using WordPress’ default URLs instead of permalinks?

May 02 2009 10:52

I think some are missing the advantages of your ‘own’ Short URL service:

1. For SEO and humans you’re still using your nice permalinks
2. For twitter you’re using a short urls
3. You’re not depending on a third party service, with the danger they vanish or go down
4. You’re not loosing your linkjuice, because you’re still using your own domain

Hope this helps…

May 03 2009 18:23

Never thought of this, great idea … but if Google indexes the “short” url of your wp posts, dont you get a duplicate content problem, if you use this to often?

May 03 2009 18:26

when your domain is short this looks really nice and I like this hack and I will use it

May 04 2009 20:05

Ah, I see what you did there. Nice one, I’ll be sure to try and use this in the future.

May 08 2009 07:15

This is useful as some of my url’s are very long, thanks, will also be useful in other ways as well.

May 08 2009 17:54

I think this is a great tip if your goal is a short url.
I like your quick tips. It sure beats wading through mounds of detail

May 11 2009 08:23

is it required any code or other tricks plz can you provide more info. ?

Jun 01 2009 12:40

To add to @Tschai’s comment…

5. Branding, which is very important if you take your blog seriously.

Jun 01 2009 15:07

I am confused only so little people get the advantage of this information.

I even pimped this idea by creating a little rewrite ule like so:
RewriteRule ^p/([^/]*)$ /?p=$1 [L]

Now I can reach my articles (wich still have the old url applied to them) their ID or something around this: http://gfries.de/p/107

This is very usefull for auto updates on twitter where you don’t want to put the whole url in your post and maybe want to avoid use of tinyurl etc.

sorry for messing up with english language :-)

Jun 02 2009 10:50

This actualy is a great advice for 2 reasons. It’s simple and useful but more importantly – smart people don’t click tinyurl links. Ever. With shortened WP link I still know what site I’m visiting. tinyurl can lead anywhere and I’m not taking a risk.

Jun 30 2009 19:22

Hey i have seen that in some of the cases tinyurl takes one to the wrong webpage……….

Nov 09 2009 14:03

Really useful article, ive just started using bit.ly instead of tinyurl because of the twitter integration and link analytics.

I can see the concern about malicious links becoming ever more an important issue as the twitter user base continues to grow at such a phenomenal speed and spammers start to cotton onto it’s potential.

Feb 04 2010 02:33

Simple and easy, good one Aytemir… and thanks to you for sharing it. :)

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required