Latest Tech and Tips

How to Exclude Pages from WordPress Search Results


By default, WordPress Search attribute presents released blog posts as well as released pages in search engine result. Often when customers are trying to find something in a blog site, it is probably an article instead of a web page. In this post, we will certainly reveal you how to make your search extra pertinent as well as much less crowded by omitting pages from WordPress search engine result.

Exclude pages frm WordPress search results

First, you include the complying with code to your style’s functions.php data or a site-specific plugin.

//Exclude pagesfrom WordPress Search
if (! is_admin()) {
feature wpb_search_filter($ query) {
if ($ query->> is_search) {
$ query->> collection(' post_type', 'article');.
return $query;.
add_filter(' pre_get_posts',' wpb_search_filter');.

Explanation: This code initial checks that the search is not coming from from the WordPress admin pages. If it is not, after that it looks for blog posts by establishing the post_type criterion.

You can additionally make it do the contrary by establishing the post_type to pages, so it just return pages in the search engine result.

We wish this post aided you discover how to exclude pages from WordPress search engine result. You might additionally desire to see our listing of finest WordPress search plugins to boost your website search.

If you liked this post, after that please subscribe to our YouTube Channel for WordPress video clip tutorials. You can additionally locate us on Twitter as well as Facebook.