Custom WordPress Posts

Do you have a custom WordPress posts page?

WordPress is a great for blogs, but what if you want your site to standout and be different.  That means you are going to have to make a custom layout and you may use CSS for your styling.  But having the styles added automatically to each post is not possible unless you add some custom php code to your functions.php file.  This will allow you to add a class to all your posts automatically and your CSS will be applied to those posts automatically too.  This is much better than grabbing the post id of each post then adding it to your CSS.

So, it is best to enter the code in the functions.php file in your child theme.  Here is an example:

// This will add a class name to the posts, so can then target by class name

function category_id_class($classes) {

global $post;

foreach ((get_the_category($post->ID)) as $category) {

$classes[] = 'Target-the-posts-page-with-some-class-name’;  //This puts the class name on each post

}

return $classes;

}

add_filter('body_class', 'category_id_class'); /* Add the class to the body of the post */

So, if you have a custom posts page, this will make the formatting of the page easy since you only have to do it once.  And then you can now focus on what's important -- your blog.

Leave a Comment





Contact Us

Do you have a question for us? We're here to help.

Subscribe to our Newsletter

Receive our newsletter with tips and exclusive deals in your email.

Left Menu Icon
530.878.1236