You may have seen the Custom Field box in WordPress when you edit a page or a post but you may not know how powerful this feature can be.
Let’s say that you have multiple pages on your website and you would like to be able to style each of them differently. Instead of making separate page templates in the theme folder, you can add a line of code to the existing template and add different classes right in the WordPress editor.
This post will assume that you would like to add a class for styling purposes, but there are many other ways Custom Fields can be used.
Very simply, if you would like to add a class variable, just paste the following line of code just like you would any other class:
class ="post->ID; echo get_post_meta($postid, 'class', true);?>"
Like the image below illustrates, just type in class for the Custom Field name, and the name of the class in the Custom Field value, then click “Add Custom Field”. The page or post that you created will now add a class name to the template.