How to Check for Class in body_class() in Wordpress

前端 未结 3 888
野性不改
野性不改 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:28

    I have had the same problem as I created pages using different templates but a custom sub-menu needed to be the same on each pages.

    I tried this one first what is failed

    >

    The extra classes was added to the body tag but when I run the error log then it was not in the classes array. So I was sure it was added later to the body tag.

    This solution worked for me:

    functions.php

    $GLOBALS['extraBodyClass'] = '';

    In the template file

    - very first line in the template file

    > - after the template name declaration

    In the header.php file

    $classes = get_body_class();
    if($GLOBALS['extraBodyClass']){
       $classes[] = $GLOBALS['extraBodyClass'];
    }
    

提交回复
热议问题