I did my WordPress website design with Elementor plugin and i included a menu in the side bar of every page, now i face a problem with search results because searching any word from the menu gives a huge number of results, it's normal because i have a menu in all pages.

I want to know how can i exclude this side menu from search result?

1 Answer 1


Copy below code and paste in function.php file to exclude pages from search results.

if (!is_admin()) {
    function wpb_search_filter($query) {
        if ($query->is_search) {
            $query->set('post_type', 'post');
        return $query;
  • Thank you for your response, but what i want is to hide a part of a page from search results page not the entire page
    – sihamxxi
    Jun 4, 2019 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.