Search result is always interpreted as is_front_page, is_home

Forums Forums Search & Filter Pro Search result is always interpreted as is_front_page, is_home

Viewing 10 posts – 1 through 10 (of 14 total)
  • Anonymous
    #190873

    The search results page is always interpreted as is_front_page or is_home. You can also see that the class home is set in the body tag.

    Due to this behavior it is not possible to use the queries is_front_page or is_home.

    From my point of view this is a bug. The option “Force is_search to always be true?” or “Force is_archive to always be true?” doesn’t help at all.

    What is the solution?
    Concrete problem: On the result page I get a slider because the page is interpreted as front_page or home.

    Translated with http://www.DeepL.com/Translator

    Trevor
    #190882
    This reply has been marked as private.
    Anonymous
    #190886
    This reply has been marked as private.
    Trevor
    #190892

    It is your theme that is doing this. I also notice that you do not seem to have an archive.php template.

    The search.php is calling the WordPress body_class() function. Using your functions.php, you can hook in to this and remove the blog and home classes. You can use force is_search to add the search body class.

    As there is no ‘real’ page called ‘filter’, your code would then look to see if the page being loaded has the search body class, and if so, remove the blog and home classes:

    add_action( 'body_class', 'my_custom_search_class');
    function my_custom_search_class( $classes ) {
        // Remove 'blog' class
        if ((in_array('blog', $classes)) && (in_array('search', $classes))) {
            unset( $classes[array_search('blog', $classes)] );
        }
    
        // Remove 'home' class
        if ((in_array('home', $classes)) && (in_array('search', $classes))) {
            unset( $classes[array_search('home', $classes)] );
        }
        return $classes;
    }

    As long as that runs after our plugin adds the search class, all should work, otherwise it might need a low priority set.

    Anonymous
    #190994
    This reply has been marked as private.
    Trevor
    #190996
    This reply has been marked as private.
    Anonymous
    #190998
    This reply has been marked as private.
    Trevor
    #191000

    Checking around, is_home and is_front_page will often return other pages IF the theme sees posts on the page, so you can get false hits. What is the code that you are using to determine of the slider is used?

    Anonymous
    #191004
    <?php if ( is_front_page() ) : ?>
    <?php dynamic_sidebar( 'slider' ); ?>
    <?php endif; ?>
    Trevor
    #191006

    What happens if you use is_home instead of is_front_page ?

Viewing 10 posts – 1 through 10 (of 14 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.