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.
Nope, this one’s beyond me. What’s a class variable?
Reply
Hmmm, if you don’t understand it maybe I worded it wrong, but I can’t think of a better way to describe it. Essentially, class variable would be a class which can be set within the WordPress editor. I’ll have to think of a better term to explain it.
Here’s the problem; I don’t know what “class” means. That’s why the rest of it doesn’t make sense. What does class refer to?
I mean a CSS class. Similar to an id. For example
Ah; see, I didn’t know that until you just told me. I hope your other folks reading this are more savvy. lol
Reply
Lol @ Mitch
Thanks Keith, i needed this info!
Reply
Thanks Glen! Glad I could help.