Forums › Forums › Search & Filter Pro › Body Classes
- This topic has 17 replies, 2 voices, and was last updated 9 years, 4 months ago by
Trevor.
-
Anonymous(Private) July 24, 2017 at 9:06 pm #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(Private) July 25, 2017 at 12:32 pm #122584This post might help you:
https://support.searchandfilter.com/forums/topic/results-page-not-loading-properly/#post-69585
Trevor(Private) July 25, 2017 at 12:51 pm #122594I 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(Private) July 25, 2017 at 5:27 pm #122656Thanks 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
<bodyand 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(Private) July 25, 2017 at 5:41 pm #122669It 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(Private) July 26, 2017 at 12:00 am #122764Thanks 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?
Anonymous(Private) July 27, 2017 at 5:40 pm #123190Here 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”:
-
AuthorPosts