Forums › Forums › Search & Filter Pro › body classes removed when filter is active
- This topic has 10 replies, 2 voices, and was last updated 7 years, 11 months ago by
Trevor.
-
Anonymous(Private) May 3, 2018 at 10:15 am #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.
Trevor(Private) May 3, 2018 at 12:37 pm #175579For me, as a logged out user, I see these classes for both pages:
archive category category-bankstellen category-4 single-author foldIn 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(Private) May 3, 2018 at 1:17 pm #175584Hi 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(Private) May 3, 2018 at 1:38 pm #175588Ah. 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.
Trevor(Private) May 3, 2018 at 1:54 pm #175598This 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(Private) May 3, 2018 at 2:25 pm #175601It’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.
-
AuthorPosts