The WordPress search is not the greatest of all searches out there. One thing that many people find annoying is that the search brings up pages instead of just posts. In general your readers will want to search for your posts a.k.a. your content. The pages aren’t needed in search because they are right in the navigation. If you have a hidden page that is not in nav, you almost certainly don’t want that coming up With this very simple step you can avoid that common annoyance and you can do it without adding a bulky plugin.
It is a good thing we already talked about the WordPress Theme Editor because you will have to access it for this step. When you are in WordPress look for Editor under Appearance and NOT Plugins.
Sometimes you want one of your pages to be hidden for some purpose. Even if you hide it form navigation it might come up in searches on your site. This technique will address that issue.
function SearchFilter($query) {if ($query->is_search) {$query->set(‘post_type’, ‘post’);}return $query;}
add_filter(‘pre_get_posts’,'SearchFilter’);
Once you add the code, click Update File and pages will be hidden from search.
Sometimes you want one of your pages to be hidden for some purpose. Even if you hide it form navigation it might come up in searches on your site. This technique will address that issue.
Leave A Reply (No comments So Far)
No comments yet