Skip to main content

Exclude WordPress Pages from Displaying In Search Page!


WordPress automatically assigns the default category to a single page. This is a simple way to exclude certain pages, for example, a contacts page, from displaying in your search results. A simple way around this is to create a new category, in this instance I have called it pages. Once the category is created hover over the newly created category and look for the cat-ID number as shown below, remember it or write it down.

Category ID

Then we need to change the default category setting so go to Settings>Writing in your admin panel and change the default category to the newly created one. The only problem is now is that if your pages have already been published they have already been assigned a category so you will have to re-publish them. Create a new page then copy and paste all the old stuff into the new page, delete the old page and save the new page. This will then assign your new default category to your page.

Now in our search.php type the following under get_header()

Replace the number with the one you wrote down but keep the minus (-) in there as this excludes the category from displaying. Your custom pages will not show up in your search page again.


%d bloggers like this: