If you have hidden pages on your blog, you may want to hide them from search results too. Here is a little trick to hide them all.

This trick uses pre_get_posts filter to remove pages from the query results. Here is the code:

// Remove pages from search results
function shailan_remove_pages($query){
	if ($query->is_search){
	return $query;

Open your functions.php file and put this snippet in. Save and upload.

After the edit is done, you can test it out by searching a page title.

This way you can make sure no pages are listed on your search results page.

Hope you like this trick. Enjoy!

Deal Notice: We are using A2 hosting for all of our websites, and we are really happy with their service. So we wanted to share you this discount link for you to try it out. If you get a hosting using this link, you will also help us build better content for you: SSD Hosting - 300% Faster Than Standard Hard Drives