• Resolved chriswarren00

    (@chriswarren00)


    Hey guys,

    I’m trying to assign a body class to some pages in order to create ‘current’ states for page links using this: <body <?php body_class( ‘x’ ); ?>

    The only way that inserting this chunk of code DOESN’T disrupt the flow of elements on the page is when I put it before the get_header call, which I seem to remember reading was a big no-no. Is this ‘legit’?

    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The <body> tag goes only in header.php, just after the closing head tag, </head>

    It won’t be in a file that includes get_header because it belongs in the header file itself, which is what get_header includes in any template file that contains it.

    That applies to using the bodyclass also.
    You are missing the closing bracket by the way, It should be
    <body <?php body_class( 'x' ); ?>>

    Thread Starter chriswarren00

    (@chriswarren00)

    Okay, that makes sense. So do I do that and then view source to see what html it generates and then use that to style page links? Thanks.

    do I do that and then view source to see what html it generates and then use that to style page links?

    yes, exactly

    you can also filter the output if you don’t find in the generated classes what you need

    Thread Starter chriswarren00

    (@chriswarren00)

    Awesome. Thanks!

    Alwyn Botha

    (@123milliseconds)

    Please mark thread as resolved so that

    – others with similar problem can see it as resolved and will read this thread for help if they

    have similar problem

    – people providing help see it as resolved and will not waste time reading this post.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Where does body_class go?’ is closed to new replies.