Add Custom Classes to Wordpress Posts

23 June 2013 on Wordpress.

While developing my latest WordPress plugin, Initial Letter, I needed to figure out how to add a custom class to the post container. While I actually didn't end using this method I figured it would be an easy thing to share in case others were looking to do the same thing.

Basically it comes down to adding a filter which ties into the ‘post_class’ hook. Keep in mind that this will only work if the theme you're using implements the post_class() function, which pretty much all themes should use.

// Add 'initial_letter_post' class to post container
function initial_letter_plugin_class_filter($classes) {
	$classes[] = 'initial_letter_post';
	return $classes;

add_filter( 'post_class', 'initial_letter_plugin_class_filter');


menuFlip - jQuery Plugin for Flipping Navigation

Here's another simple WordPress plugin I came up with. I was trying to figure out an easy way to create a text box for some song lyrics which, once clicked, selected everything inside so anyone could easily copy and past the contents. Well, once I figured out how to make it I figured I would make it easier for others who want to do the same thing. Hence, Simple Select All Text box was born.


Delete Duplicate WordPress Comments

I ran into a situation recently where all of the comments on a blog I was working on got doubled up, so I had to figure out a way to get rid of the extra ones. I read some solutions involving using two MySQL tables but I was hoping to avoid dealing with all that.