Automatically post friendly URLs to Twitter and Facebook

January 12th, 2008 Jason

In a fit of self-propagation, I set about this week to explore making Wordpress post to my Twitter any time I update.

I found a basic, but functional, plugin called Twitpress, which does exactly what I wanted. Except…I’m also using the All In One SEO Pack, which rewrites page URLs into an SEO-friendly format. (Really, a must-have plugin.) Twitpress by default will tweet the stock version of a post URL:

http://RelevantText.com?p=24

instead of the format I want to show:

http://RelevantText.com/making-the-most-of-server-errors-20080111/

Now, I know that a)Twitter links are nofollowed, so this doesn’t really matter for the spiders, and b)Twitter also automatically turns long links into tinyurls, but it still bothered me (more on why in a minute). So, I set about to fix the plugin.

After reading through what the plugin code was doing, I surfed through the WP database tables a little bit, and discovered that I needed to change one line in Twitpress. Hooray!

In the twitpress.php code, replace line 85:

$proto = str_replace("[link]", get_option('home')."?p=".$postID, $proto);

with

$proto = str_replace("[link]", $post->guid, $proto);

‘guid’ is a field in the wp_posts table, if you care.

Bingo. I’m very pleased with myself.

So why, you may ask, do I care about how the links look in Twitter if they aren’t spiderable? Because I’ve also installed the Twitter App on Facebook, so any time I update Twitter, my Facebook status updates as well…which means the link is then being pushed out along the newsfeeds of all my contacts there. The link is still not spiderable, but it is potentially much more likely to get seen, followed, and possibly linked to. Through the tinyurl redirect, it now goes to the right version of the URL, and when people subsequently link to the post, I want them using the right one. This, I think, will help that along.

Jan 14 Update: After my initial excitement, I’ve discovered that this is still slightly buggy – notifications occasionally appear on twitter with the p= URL, and sometimes with no URL at all.  This seems to only happen when a post is first published, and not when later edited, but I’m not clear why, as the ‘guid’ field is populated with the first publish of a post. So, this is cool when it works, but I’m still looking at it. 

Posted in Facebook, Twitter, geek, php, plugins, seo, site, wordpress | No Comments »

On setting up a new WordPress blog

September 4th, 2007 Jason

I was impressed that wordpress pretty much installed in two steps. Template management has been a piece of cake (browse, download, activate), as has installing plugins.

Because sometimes it’s interesting to know, I’ve got the following plugins installed:

All-In-One-SEO pack
Because I’m working in SEO right now, I’m paying attention to this kind of stuff, and it’s best to have it set up properly right off the bat. One thing I never bothered to resolve on the old blog setup was setting individual page titles for each post. Wouldn’t have been that hard to do, though the way I’d set up the original Dreamweaver template system did throw in some challenges. But I’m moved away from that template now, and this plugin will help keep this part straight.

Did You Pass Math?
A comment-spam protection plugin. A simple math question must be answered before a comment can be posted, which should prevent spambots from commenting. Of course, you need to register to comment anyway, so I’m guessing I’m safe.

NoFollow Case-by-Case
More SEO stuff. The default on wordpress is to render all links in comments with the “nofollow” attribute; this deactivates that default and gives that control to me.

Then I’m doing other customizations on my own.

I wanted to keep the basic look and functionality of my home page, presenting just the latest post in a separate box. The best way I could come up with in two minutes of thinking about it was to display from the wordpress RSS feed. Piece of cake. The snippet takes the RSS feed from the wordpress blog, and processes it using the MagpieRSS library, which I’ve used before but was pointed to again by this post. Magpie parses the RSS into a standard PHP array. so it can be manipulated and styled in whatever way you like. To avoid exactly duplicating the content, I’m trimming the posts using some basic substring manipulation I found in the PHP documentation. (It’s possible that the RSS is supposed to do this trimming, but I’m not sure that it does, so I figured I’d just have some fun with it anyway.)

What remains to do is actually muck about with the template and styling of the wordpress sections of the site now, so I can make it better match the existing areas that I don’t want to throw away. This isn’t likely to be a public post until after that’s a little more settled, so by the time you read this it’ll probably all be fixed, and for all I know the subject of another post.

Posted in geek, php, site, wordpress | No Comments »