• Resolved awtd

    (@awtd)


    I’m trying to add a class to the body of my Storefront child theme, and it doesn’t seem to be working. I’m using a bog-standard function copied and pasted from the web, which works just fine if I put it in the Storefront theme’s functions.php but doesn’t work at all when I put it in my child theme’s functions.php. I’ve got no problem doing other standard things like enqueuing scripts and styles from the child theme, but this one just silently fails. What’s going on?

    add_filter( 'body_class', 'my_class_names' );
    function my_class_names( $classes ) {
        // add 'class-name' to the $classes array
        $classes[] = 'casfassafasd';
        // return the $classes array
        return $classes;
    }
    • This topic was modified 4 years, 8 months ago by awtd.
    • This topic was modified 4 years, 8 months ago by awtd.
Viewing 5 replies - 1 through 5 (of 5 total)
  • your function works fine in my test install in a storefront child theme (no woocommerce installed).

    how and in what page are you checking for the body_class?
    do you also have woocommerce installed and enabled?

    Thread Starter awtd

    (@awtd)

    Turns out the problem is Firefox Dev Console. The inspector view is shortening long text strings, such as the string of classes in the body. How… helpful of them to do that.

    using ‘view source’ or similar (on right-click) is also a good way of checking the html output of any web page in your browser … including checking for CSS classes and ids …

    HI I HAVE LOOKED EVERYWHERE BUT COULD NOT FIND SOLUTION. NEED TO CUSTOMISE HOME PAGE LITTLE BIT.
    IT WOULD BE NICE I CAN GET HELP FOR FOLLOWING ISSUE
    1) PLACE SEARCH BAR ON BODY. JUST UNDER THE PAGE NAME (Your favorite food, delivered with Foodhouse!)
    2) IT WOULD BE GREAT I CAN HAVE BUTTON WITH IT.

    @shayed I already replied on the thread you created, please see my response there

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘body_class not working in Storefront child theme?’ is closed to new replies.