WordPress: Twitter Friendly Links Plugin. Stage Two

Hey there! I'm currently working on a CLI tool to deploy WordPress apps to DigitalOcean. Check it out! It's free and open source.

Missed the beta? No problemo! Just a flashback – the plugin transforms permalinks on your blog into short fancy links within your own domain name: https://konstantin.blog/wordpress/plugins/twitter-friendly-links/ into a short and Twitter friendly https://konstantin.blog/712 similar to what TinyURL does, remember?

I’ve updated the plugin a couple of hours ago to version 0.2. The new key features are the “Twitter Stuff” form in your edit post page, with the shortlink and an example of the message to Twitter, with a link that takes you directly to Twitter with the predefined text not more than 140 characters. Very handy indeed.

Here’s the plugin page by the way: Twitter Friendly Links and don’t forget to check out the screenshots!

Next. You might have noticed that I got a new line just under the tags list in every post – shortlink. I’ve added a function to the plugin called twitter_link() which returns the short link for a post when used within the loop. Here’s my code snippet in single.php:

if (function_exists("twitter_link")) {
    echo 'Shortlink: <a href="'.twitter_link().'">'.twitter_link().'</a>';

Make sure you use the function_exists() function to check before using, otherwise you’ll get an error message if for some reason the plugin is missing or deactivated (if you’re a Theme developer for instance).

One more thing. Most of you know Joost de Valk and his Sociable plugin. There’s a TwitThis button which takes you to Twitter.com and the predefined tweet text is simply the permalink of your post. Digging his well-written php code I managed to add my own button called Twitter, that does the same, but the predefined text is the title of the current post plus the shortlink, all trimmed to 140 characters.

So here’s my version of sociable.php (just replace the one in your plugin). Changes are on lines 518-522, 631-650 and 681. Please do not use this version of sociable.php unless you use the Twitter Friendly Links plugin, cause I haven’t written any checks before using the functions. Joost might consider this extension then polish it off in the next updates. The Twitter button may then be chosen from the Sociable section in your WordPress Settings.

About the author

Konstantin Kovshenin

WordPress Core Contributor, ex-Automattician, public speaker and consultant, enjoying life in Moscow. I blog about tech, WordPress and DevOps.