Community Forums › Forums › Design Tips and Tricks › Adding css class for posts
This topic contains 11 replies, has 2 voices, and was last updated by SoZo 4 months, 2 weeks ago.
-
AuthorPosts
-
January 30, 2013 at 1:54 pm #16476
I want to use a custom css class for some posts using the news theme. Where would I put the css class code?
There is a field called Custom Post Class on each admin post page, how would that field be used?
Thanks,
Bob
January 30, 2013 at 1:57 pm #16478That is where you can you can add your custom class
John “Nicolas Flamel” Wright | SoZo’s design| John Wright Photography
January 30, 2013 at 2:04 pm #16482Ok, I see your response, but I don’t see the answer that you were referring to.
January 30, 2013 at 2:04 pm #16484Add the class in the Custom Post Class field
John “Nicolas Flamel” Wright | SoZo’s design| John Wright Photography
January 30, 2013 at 2:05 pm #16486Ok, I see, You were referring to the Custom Post Class. So I would paste the class code into the 1 line field? Doesn’t 1 line make it hard to read what is in that field?
January 30, 2013 at 2:10 pm #16488Will the class entered into the Custom Post Class field only be available to that single post? If so how can I make the class global so other posts can use it?
January 30, 2013 at 2:12 pm #16489Ya, the field is only for each post. To add a class you can use this
function add_body_class( $classes ) { $classes[] = 'YOUR_CLASS_GOES_HERE'; return $classes; }You need to put that into an action with conditional tag to limit where it’s output.
John “Nicolas Flamel” Wright | SoZo’s design| John Wright Photography
January 30, 2013 at 2:17 pm #16494Ok, so where would I put that code?
Is there any written documentation on adding css classes?
I don’t think I need to limit it’s output, I will refer to the class in the post content.
January 30, 2013 at 2:20 pm #16497You can put it in functions.php. Without a conditional it would add the class to every page of the site.
This should help.
John “Nicolas Flamel” Wright | SoZo’s design| John Wright Photography
January 30, 2013 at 2:34 pm #16506Ok, That helped. How would I change, for example, the font-size on all posts on the site?
January 30, 2013 at 3:19 pm #16513What would be the reason one would want to use the functions.php to add a custom body class rather than adding the class code to the end of the style.css file?
January 30, 2013 at 4:06 pm #16524Not sure I follow. If you want to add a new style rule then you add it to the style sheet, where all styles should go. If you want to add a custom body class to a page then that is PHP. PHP does not go in CSS.
John “Nicolas Flamel” Wright | SoZo’s design| John Wright Photography
-
AuthorPosts
You must be logged in to reply to this topic.