Categories

Blog and other Rantings

Modifying Twitter Tools for Wordpress to use Search Hash Tags
Category: Tutorials | Wednesday, 30 July 2014 19:29

wordpressI've recently branched out into the whole new word of WordPress, well it's new to me anyway! It is definitely a useful tool, not quite as powerful as Joomla, but still powerful in its own right. In terms of blogging, it has to be the best!

A new site I've been working on posts over 100 articles per day. What better way to spread the word than to have an update automatically posted to Twitter. Luckily enough there are many people who have come up with this idea already. If you use WordPress.com to host your blog then this functionality comes built in, but for the rest of us we require a third party plugin.

The best one I have come across is called Twitter Tools by Alex King. One of the particular highlights of this tool for me is it allows you to enter a Twitter Application API code. What does this mean? Many "blog to social media sites", such as ping.fm, leave subtle hints everywhere that you have used their services to post your tweet. What Twitter Tools for Wordpress allows you to do is submit a tweet using your own application, meaning you take all the credit. It creates a more professional look on your Twitter page and makes it less obvious that your tweets aren't being typed by hand.

What is a hashtag and why should I use it?

Now posting your new article to Twitter is one thing, but exposing it to as many twitterers as possible is another. By default most Twitter users opt to show tweets from only users they follow. Think of a hashtag as another name for a keyword. Twitterers use hashtags to identify keywords for their tweet. Of course you are limited to 140 characters, so you need to keep it short and sweet. By using hash tags the Twitter community came up with a way to relate posts and create trends. Any one can see these tweets so by using hashtags you are widening your audience in a targeted fashion.

The Code

I have implemented this on a Wordpress 3.1.3 installation with Twitter Tools version 2.4. After installing the plugin, you'll need to enable the Twitter Tools - Hashtags plugin. After installing Twitter Tools, go to the plugins page in your WordPress site and click on edit under the Twitter Tools Hashtags plugin.

Scroll down to the aktt_hash_do_blog_post_tweet($tweet, $post) function.

Comment out the line:


$hashtags = get_post_meta($post->ID, '_aktt_hash_meta', true);

Paste the code below:

	$hashtags = get_the_tags($post->ID);
$hashtags_tmp = "";

if ($hashtags) {
foreach($hashtags as $tag) {
$hashtags_tmp .= '#' . $tag->name . ' ';
}

$hashtags = $hashtags_tmp;

} else {

$hashtags = get_post_meta($post->ID, '_aktt_hash_meta', true);
}

That's it!

Disclaimer: Always backup and files you modify. This modification is in no way affiliated with the owner of of this script. I am not responsible for and problems caused!

But hold on a second, there is already a plugin that can post hashtags! Why the hell do I need to modify the code? There is a simple reason for this. The built in plugin allows you to manually type in hashtags for each article, or a standard set of hash tags for all articles. The problem comes when you use an RSS aggregator on your website, such as WordPress RSS Poster. This modification will use the keywords you have preset for your articles as hash tags so you don't need to manually edit each article after it has been posted to set custom tags. The less work the better, right?

Download Twitter Tools through the Wordpress Plugins page here. Make sure to enable the bit.ly plugin to shortern those URLs and give you more room for those keywords!