Forums Forums Search & Filter Pro body classes removed when filter is active

Viewing 10 posts - 1 through 10 (of 11 total)
  • Anonymous
    #175524

    Hi there,

    We are using the search and filter plugin for our client and everything is working fine except for one thing. When you are on a category page and there is no filter active, the body class is like this, which is good:

    <body class=”archive category category-bankstellen category-4 logged-in admin-bar single-author fold customize-support”>

    But then when you click a filter (for example a specific brand), the filter loads the products perfectly fine. But if you click to go to page 2 of the filter results, all the body classed are removed and the body class looks like this:

    <body class=”blog logged-in admin-bar paged-2 single-author colon customize-support”>

    Why is this happening and how can we solve this problem?

    Thanks and please let me know.

    Anonymous
    #175526
    This reply has been marked as private.
    Trevor
    #175579

    For me, as a logged out user, I see these classes for both pages:

    archive category category-bankstellen category-4 single-author fold

    In the form design, the last settings tab is ‘Advanced’. See what happens if you check (ON) the Force is_archive to always be true? setting.

    Anonymous
    #175584

    Hi Trevor,

    Thanks for your response. I’ve checked the option you’ve mentioned. As you said when you visit the page as logged out user, in the first instance the body looks like this:

    <body class=”archive category category-bankstellen category-4 single-author fold”>

    But then if you check “Novastyl” the body class is still the same, but the problem comes when you click the second page (with the option ON which you mentioned), the body class looks like this:

    <body class=”blog archive paged-2 single-author colon”>

    So it removes all the category classes, but our design is based on the categories so when you click the second page there is no header image anymore for example. Can we set the filter so that the body classes are always the same, even when you click the next page?

    Trevor
    #175588

    Ah. The classes are added by your theme, somewhere in the theme templates. Which of the classes do you need, as some will change I would think and some are not needed? I think there is a function in WordPress that allows you to do this, as long as you are using a child theme.

    Anonymous
    #175592

    The most important classes are “category”, and “category-bankstellen” is the category-specific class. If it’s somehow possible to keep this as body class, i think then the problem is solved.

    Trevor
    #175598

    This help page shows how:

    https://wordpress.stackexchange.com/questions/250185/remove-and-add-class-with-body-class-function

    But it need to be inside an is_page() function so that it only triggers on the results page like this:

    
    add_action( 'body_class', 'my_search_classes');
    function my_search_classes( $classes ) {
      if ( is_page( 'bankstellen' ) ) {
        // Remove 'blog' class
        if (in_array('blog', $classes)) {
            unset( $classes[array_search('blog', $classes)] );
        }
    
        // Remove 'home' class
        if (in_array('home', $classes)) {
            unset( $classes[array_search('home', $classes)] );
        }
    
        // Add custom class (or add more with array_push)
        $classes[] = 'my-custom-class';
      }
        return $classes;
    }

    This goes in the child theme functions.php

    Anonymous
    #175601

    It’s about this link: http://149.210.146.253/~wooncentru/bankstellen/?_sfm_merk=Novastyl&sf_paged=2

    At this link, i filtered on brand (Novastyl) and this link is on page 2 of the results.

    On this page, the body classes are looking like this with the function above added:

    <body class=”blog archive paged-2 single-author”>

    As you can see, there are no category related body classses.

    This link is when you are on page 1 of the results:

    http://149.210.146.253/~wooncentru/bankstellen/?_sfm_merk=Novastyl

    And the body classes are like this:

    <body class=”archive category category-bankstellen category-4 single-author”>

    As you can see, here the category related body classes are present.

    In our theme we didn’t do anything with adding or removing body classes, this is pure wordpress standard output with no modifications.

    So when you navigate through search results pages, somehow the category related body classes are removed.. That is the problem that we have at the moment.

    Trevor
    #175604
    This reply has been marked as private.
    Anonymous
    #175607
    This reply has been marked as private.
Viewing 10 posts - 1 through 10 (of 11 total)