How to Check for Class in body_class() in Wordpress

前端 未结 3 887
野性不改
野性不改 2020-12-15 22:48

Within Wordpress header.php, I have

>

How do check to see if a specific class exists, and th

3条回答
  •  无人及你
    2020-12-15 23:32

    If you really, really need to use different markup based on the body_class classes, then use get_body_class

    $classes = get_body_class();
    if (in_array('home',$classes)) {
        // your markup
    } else {
        // some other markup
    }
    

    But there are probably better ways to do this, like @Rob's suggestion of Conditional Tags. Those map pretty closely to the classes used by body_class.

提交回复
热议问题