Stephanie Leary

Writer and WordPress consultant

  • Books
    • Content Strategy for WordPress (2015)
    • WordPress for Web Developers (2013)
    • Beginning WordPress 3 (2010)
  • Blog
    • Fascism Watch (2016-17)
    • Content Modeling for WordPress series
    • WordPress Hidden Gems series
  • Work
    • Portfolio
    • Services
    • WordPress Plugins
    • WordPress Themes
    • Presentations and Interviews
    • on GitHub →
  • About
    • Press Kit
  • Contact
    • Mailing List

Why you don’t need to roll your own link shortener

July 4, 2009 Stephanie Leary 1 Comment

permalink-default-setting

Everyone wants the shortest links possible, mostly thanks to Twitter. There are a number of tutorials on creating your own link shortening service, and for WordPress sites, the Link Shortcut plugin is the most popular option.

You don’t need it.

If your domain (including the http) is under 24 characters or so, you can use the default permalink format. It works even if you’re using another permalink structure.

Just add this to your theme file and you’re done:

<p>Sharing this post? The short URL is
<?php
$url=get_bloginfo('url').'/?p='.$post->ID;
echo '<a href="'.$url.'">'.$url.'</a>';
?></p>

If your domain is too long, then hosting your own link service isn’t going to help. Twitter shortens URLs longer than 30 characters. You need to set aside 6 to 8 characters for the post ID (“/?p=123”), depending on how many posts you have. If your domain alone is longer than 22 to 24 characters, your shortened links will be too long for Twitter anyway — and it’s unlikely that a shortener plugin will get it much shorter than that. You can register a shorter alternate domain, or you can resign yourself to incoming links from third party shortening services.

WordPress Permalinks, short links

Comments

  1. Michel says

    August 16, 2009 at 10:35 am

    Good idea! And will work easily on most WP-based websites:)

    Thank you for sharing!

    (And maybe WP themes nowadays should have something like this built-in…)

    Reply

Leave a Reply to Michel Cancel reply

Your email address will not be published. Required fields are marked *

Latest WordPress Book

Content Strategy for WordPress

A short book for content strategists and managers on implementing a complete content strategy in WordPress: evaluation, analysis, content modeling, editing and workflows, and long-term planning and maintenance.

Read the sample chapter

Kindle Nook iBooks Kobo Smashwords

WordPress for Web Developers

WordPress for Web Developers (9781430258667)

This is a book for professional web designers and developers who already know HTML and CSS, and want to learn to build sites with WordPress. The book begins with a detailed tour of the administration screens and settings, then digs into server-side topics like performance and security. The second half of the book is devoted to development: learning to build WordPress themes and plugins.

This is the second, much-revised and updated edition of Beginning WordPress 3, with a more accurate title. Everything’s been updated for WordPress 3.6.

WordPress for Web Developers is out now. See what's inside...

The best WordPress features you’ve never noticed

  • WordPress Hidden Gems: Screen Options
  • WordPress Hidden Gems: Bulk Edit
  • WordPress Hidden Gems: Private Status
  • WordPress Hidden Gems: Dashboard Feed Readers
  • WordPress Hidden Gems: Options.php

Content Modeling for WordPress series

  • Content modeling for WordPress, part 1: analyze content
  • Content modeling for WordPress, part 2: functional and organizational requirements
  • Content modeling for WordPress, part 3: a sample content model

This is an excerpt from Content Strategy for WordPress.My latest books are Content Strategy for WordPress (2015) and WordPress for Web Developers (2013). Sign up to be notified when I have a new book for you.

Copyright © 2022 Stephanie Leary