WordPress: Tweet Shortened URL of Current Page to Twitter

A month or two ago I had an interesting idea involving WordPress permalinks. I realized that is would be very simple to automatically shorten WordPress permalinks for usage on Twitter. With a little .htaccess tweak, you could have something like yourdomain.com/s123 redirect to yourdomain.com?p=123. The default WordPress permalinks always work, and will forward to your preferred permalink. You end up with an easy way to have a short link for each of your posts, and it’s all self-contained within WordPress. No third-party services.

It seems that while I put-off writing a post on how to do that, everyone else had a similar idea. After several posts on some more complex solutions involving plugins and things, 5ThirtyOne put up a post very close to my original concept. Rather than steal Derek Punsalan’s thunder, I will point you in the direction of WordPress: Tweet Shortened URL of Current Page to Twitter.

One of the most requested pieces of code from the current iteration of 5thirtyone.com are the share links accompanying each article. Each link automatically grabs the current URL & title (if applicable) for the post or page and broadcasts it to the selected social network. This particular tutorial focuses on sharing your content via Twitter. By the end of this tutorial, you and your readers will be able to send content to Twitter directly from a WordPress page using a shortened version of the URL without a plugin.