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.
Discover more from WorldOWeb
Subscribe to get the latest posts sent to your email.
Sadly this doesn’t seem to work in WP 3.0.1
Hi Ridgey28:
This clever technique absolutely works for taking certain pages out of my local WordPress search. But I see now that it seems to have taken those pages out of the search engine searches also. Actually this not the result I was looking for. I want the pages to be hidden from my local WordPress search (because they are irrelevant to the main objective of the blog), but I would like them indexed by the search engines so that people can find them and go directly to those pages. People finding the pages through a search engine would not care that the pages aren’t related to the blog.
Any thought about how I might accomplish this objective?
Thanks.
Jeff
I use Google (XML) Sitemap Generator plugin. Then in the XML-Sitemap settings in admin I unchecked the the excluded category in the excluded items box!
This technique is exactly what I needed, and I never would have figured it out on my own.
I have a main website to provide information about Washington DC. I wanted to have some separate pages as a specialized and completely unrelated reference site for a particular type of pottery. I thought I had solved the problem by hiding the pages in the bar menu at the top and in the left side menu. Then I searched for Rhino, looking for my entry about a bar by that name in DC, and I was surprised when the page with information about the pottery rhino figure popped up.
Now with your useful and effective technique, people looking for information about DC will never need to know about the unrelated pottery information. People looking at the pottery reference pages can navigate to the main site if they want.
Main site (with no access to unrelated reference pages): http://www.StationStart.com
Tremar Pottery Reference Pages: http://www.StationStart.com/tremar-pottery/
Thanks for your help.
Exellent, just genius stuff, even a dummi like me could do this (I have spent an hour to finally find out on google that there is no other solution but to put my nose into PHP using your tip) and an hour more to get this thing working… cause i do not have a SEARH.PHP in my version of WP, so at last i did IT! I’ve put your bit of code instead of the SEARH.PHP into INDEX.PHP via the dashboard of the WordPress (Appearence–Editor–Main Page Template Index.php)
Just thank you! I’ll go to bed a little bit smarter tonight.
I am glad you liked it Serge.
© 2024 WorldOWeb. All rights reserved