Add a custom class name to post_class()

If you are a WordPress theme developer ya may have ran into the need of adding custom class names to your posts. As you know WordPress normally inserts a lot of class names for posts, pages, categories, and custom post types. But in some situations, you´d prefer to add your own specific classes to target them in your CSS styles.

Adding custom classes is really easy. WordPress uses the post_class() function, which you can also use to add a new class name to the default WordPress classes.


As you can see we are passing the parameter ‘movies’ through the native  WordPress post_class() function. You can name your class names anything you want.

This is how it actually looks like inside posts loop. You can customize everything to you liking.

<?php if ( have_posts() ) : ?>
	<section class="content">
		while ( have_posts() ) : the_post();?>
			<article <?php post_class('movies'); ?>>
				<h2><a href="<?php the_permalink();?>" ><?php the_title();?></a></h2>
				<?php the_content();?>
			<?php wp_link_pages();?>

	<?php endwhile;?>

<?php endif; ?>