Adding css class for posts

Community Forums Forums Design Tips and Tricks Adding css class for posts

This topic is: not resolved

This topic contains 11 replies, has 2 voices, and was last updated by  SoZo 1 year, 9 months ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #16476

    Bob
    Participant
    Post count: 6

    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

    #16478

    SoZo
    Moderator
    Post count: 1573

    That is where you can you can add your custom class


    John “Nicolas Flamel” Wright | SoZo’s design| John Wright Photography

    #16482

    Bob
    Participant
    Post count: 6

    Ok, I see your response, but I don’t see the answer that you were referring to.

    #16484

    SoZo
    Moderator
    Post count: 1573

    Add the class in the Custom Post Class field


    John “Nicolas Flamel” Wright | SoZo’s design| John Wright Photography

    #16486

    Bob
    Participant
    Post count: 6

    Ok, 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?

    #16488

    Bob
    Participant
    Post count: 6

    Will 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?

    #16489

    SoZo
    Moderator
    Post count: 1573

    Ya, the field is only for each post. To add a class you can use this

    [php]function add_body_class( $classes ) {
    $classes[] = ‘YOUR_CLASS_GOES_HERE’;
    return $classes;
    }[/php]

    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

    #16494

    Bob
    Participant
    Post count: 6

    Ok, 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.

     

     

    #16497

    SoZo
    Moderator
    Post count: 1573

    You 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

    #16506

    Bob
    Participant
    Post count: 6

    Ok, That helped. How would I change, for example, the font-size on all posts on the site?

     

     

    #16513

    Bob
    Participant
    Post count: 6

    What 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?

    #16524

    SoZo
    Moderator
    Post count: 1573

    Not 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

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.