Categories: WordPress

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.

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.

Share
Published by
Tracy Ridge

Recent Posts

Hot New Web Dev – November 2024

Welcome to Hot Web Dev November 2024, featuring the latest technology and web development news.… Read More

3 weeks ago

Hot New Web Dev – October 2024

Welcome to Hot Web Dev October 2024, featuring the latest technology and web development news.… Read More

2 months ago

New Svelte 5 Guessing Game 2024

In this tutorial, you’ll build a fun and interactive guessing game using Svelte 5, the… Read More

3 months ago

Hot New Web Dev – September 2024

Welcome to Hot Web Dev September 2024, featuring the latest technology and web development news.… Read More

3 months ago

New JavaScript Guessing Game 2024

The JavaScript guessing game tutorial is a simple beginner's project. It features modern JavaScript syntax… Read More

3 months ago

Hot Web Dev – 12 Useful Top Tools of 2023

If you have been following the monthly Hot Web Dev magazine you will find the… Read More

3 months ago