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.
Step #2:
Now scroll down the page and you will find Layout Settings.
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 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.
Leave a Reply