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');