WordPress Hack To Enter Embedded Tags Using Desktop Blog Client To Your WordPress Posts

Few days back, a user asked me how to enter tags in WordPress, when using desktop blog clients, like blogjet, blogdesk, Windows Live Writer etc. Though WLW has plugins that help adding tags to WordPress, but Blogjet etc. clients dosen't support add-ons.Well, there's a WordPress plugin called "Simple Tags," that offers helps you manage your […]

Few days back, a user asked me how to enter tags in WordPress, when using desktop blog clients, like blogjet, blogdesk, Windows Live Writer etc. Though WLW has plugins that help adding tags to WordPress, but Blogjet etc. clients dosen't support add-ons.

Well, there's a WordPress plugin called "Simple Tags," that offers helps you manage your WP 3.0+ tags: Tags suggestion, Mass Edit Terms (Tags and Category), Auto link tags, Embedded tags ([tags]tag1, tag2[/tags]) for compatibility with old plugins, and more.

But it's quite bulky, if you're low on resources, and only need to add embedded tags in to your WordPress posts.

I've searched around my archive and found the following that help you adding the embedded tags wrapped in between[tags]…[/tags] tags into your posts, using any desktop blog client.

You can copy the code and save it in your plugins directory, enable it, and your ready to go:

<?php
/*
plugin name: embedded tag
*/
$findtagregex ="" '/(\\[tag\\](.*?)\\[\\/tag\\])/i';
$findtagsregex ="" '/(\\[tags\\](.*?)\\[\\/tags\\])/i';
class embeddedtags {
	function saveembeddedtags($postid) {
		global $findtagregex, $findtagsregex;
		$post ="" &get_post($postid);
		preg_match_all($findtagsregex, $post->post_content, $matches);
		foreach ($matches[2] as $match) {
			foreach(explode(',', $match) as $tag) {
				if ($tag != '') {
					$tags[] = $tag;
				}
			}
		}
		preg_match_all($findTagRegEx, $post->post_content, $matches);
		foreach ($matches[2] as $match) {
			foreach(explode(',', $match) as $tag) {
				if ($tag != '') {
					$tags[] = $tag;
				}
			}
		}
		wp_set_object_terms($postID, $tags, 'post_tag', true);
	}
	function ReplaceEmbeddedTags($thecontent) {
		global $findTagRegEx, $findTagsRegEx;
		$thecontent = preg_replace($findTagsRegEx, '', $thecontent);
		$thecontent = preg_replace_callback($findTagRegEx, array('EmbeddedTags','TagReplacementCallback'), $thecontent);
		return $thecontent;
	}
	function TagReplacementCallback($matches) {
		$tags = explode(',',$matches[2]);
		$tagstr = '';
		$first = true;
		foreach ($tags as $tag) {
			if ($first === false) {
				$tagstr .= ',';
				$first = false;
			}
			$tagObj = get_term_by('name', $tag, 'post_tag');
			if ($tagObj) {
				$tagStr .= '<a href="' . get_tag_link($tagObj->term_id) . '" rel="tag">' . $tagObj->name . '</a>';
			} else {
				$tagStr .= $tag;
			}
		}
		return $tagStr;
	}	
}
add_filter('the_content', array('EmbeddedTags', 'ReplaceEmbeddedTags'));
add_action('save_post', array('EmbeddedTags','SaveEmbeddedTags'));
?>

Credit for the code goes to the author.

To display tags inside your post, you can use deafault WordPress code, anywhere in your post template:

[tags]desktop, blog client, blogjet, blogdesk, ecto, embed, embedded tags, tags, tag, tagging, technorati tags, posts, wordpress posts[/tags]