Body Classes

Forums › Forums › Search & Filter Pro › Body Classes

Viewing 10 posts – 1 through 10 (of 18 total)
  • Anonymous
    #122511

    Hi! I thought this was the answer to my problem, as I too need to add a class to search results pages and thus edits to the results.php file were not sufficient. However, when I try a version of the above code, my site goes blank. Here’s what I was trying:

    add_filter( 'body_class','my_body_classes' );
    function my_body_classes( $classes ) {
     global $sf_form_data;
    	if ($sf_form_data -> is_valid_form() )
    	{		
    		$classes[] = "test-class";
    	}
        return $classes;
         
    }

    When, however, I used this more basic version that simply adds a class to any page, it worked:

    add_filter( 'body_class','my_body_classes' );
    
    function my_body_classes( $classes ) {
     
    global $sf_form_data;
    	$classes[] = "woocommerce-page";
        return $classes;
         
    }
    

    I do realize this isn’t really in your range of support, but since the check for “sf_form_data” is what makes my site break, I figure you’re the only people I can really ask about it.. 8^)

    Hope the answer is simple! Thanks for any help you can provide.

    Trevor
    #122594

    I have split this thread from the original thread, which was this:

    https://support.searchandfilter.com/forums/topic/wp-4-2-1-update-affecting-plugin/

    Anonymous
    #122656

    Thanks Trevor. I’m getting similar problems to those described here:

    https://support.searchandfilter.com/forums/topic/new-error-fatal-error/

    In that I get a fatal error – $searchandfilter does not exist.

    I notice that the page code stops “nearly” at the end of the opening body tag – it just says <body and that’s all that gets written – thus the blank page.

    Taking a cue from the other (now closed) thread, I tried swapping

    return $classes;

    with

    if(!isset($searchandfilter))
    {
        return $classes;
    }

    But I still get the fatal error.

    Again as per the other thread, S&F is definitely running; I can’t imagine what else would be “trying to access it before the action plugins_ready is fired”. Does it matter where in my functions.php I put the code?

    Trevor
    #122669

    It might need triggering later in the page load, so try changing this line:

    add_filter( 'body_class','remove_my_body_classes' );
    

    to

    add_filter( 'body_class','remove_my_body_classes', 1000 );
    

    The Codex for this function is here (it is a WordPress function, not from Search & Filter):

    https://developer.wordpress.org/reference/functions/body_class/

    Anonymous
    #122764

    Thanks Trevor but I’m afraid I still get the blank screen.

    I notice also there is this error:

    Fatal error: Call to a member function active_sfid() on null in /home/content/p3pnexwpnas09_data02/81/3413981/html/wp-content/themes/whitelight-child/functions.php on line 51

    …but I assume this is due to the undefined variable?

    Trevor
    #122839

    That would tend to suggest that Search & Filter is not active on that page, or at least not at that point.

    Anonymous
    #123072

    That’s odd as it’s the results page for a Search & Filter search.

    Would sharing a link help?

    Trevor
    #123091

    More likely it will need for Ross, the developer to take a look. So, let us work towards that. A link with the page in question first then.

    Anonymous
    #123190

    Here is the search page where the search is initiated:

    http://escape2ski.com/ski-area-search-tool/

    …and the results page, which has a body class of “home”:

    http://escape2ski.com/search-results/

Viewing 10 posts – 1 through 10 (of 18 total)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.