Website Guider

The Ultimate Resource for WPadmins and Geeks

How To Add Custom Post Class in Genesis Framework

Sometimes, as a Genesis framework user, you may feel the need of adding a custom class to a specific post. So, how do you do that? Let me walk you through this tutorial that shows you how do it while using Genesis option and code snippet. 

Add Custom Post in Genesis using Layout feature

If your website is running on Genesis Framework, you don’t have to worry about using code. Because the Genesis theme has built-in option to apply custom post class to specific post.

In order to add a custom specific post class, follow the instructions.

Step #1:

The process is easy. Remember you can apply specific custom class to a post when you are updating or writing it. So you have to edit the post you want to have a custom class.

Navigate to All Posts and start editing the post you want to apply the class. In my case, I am choosing WooCommerce SEO in 2019.

Add Custom Post Class in Genesis Using Layout Feature

Step #2:

Now scroll down the page and you will find Layout Settings.

Add Custom Post Class in Genesis Using Layout Feature

Step #3:

There you will find three options and you have to enter the custom class name into ‘Custom Post Class’. When you update or publish the post, the class will be added.

Add Custom Post Class in Genesis Using Layout Feature

Add Custom Post Class in Genesis Using Code Snippet

I know the easiest way to add the class is using theme options panel. But sometimes we need more features so in that situation we use code snippets.

In order to add a specific class on specific post, we will target it by post id. Below is the code to add custom class.

add_filter('body_class','wg_specific_post_class');
function wg_specific_post_class(array $classes) {
if(is_single('1390') ) {
$classes[] = 'custom_class';
return $classes;
}
}

Here I am inserting a class named as custom_class inside single quotes. So you have to change the name of the class whatever you want.

All this was the procedure of adding custom post class in genesis.

I hope you loved this tutorial. Please leave recommendations and questions by using comments section. Also, don’t forget to share it.

Raashid Din Dar

Raashid Din Dar is a web developer and designer. He specialises in WordPress Theme and Plugin development. Also, Web Designing is what he loves.He loves to read books and play with friends.

Leave a Reply

Your email address will not be published.

Back to top