Feb 11, 2008 @ 12:41 PM
Discuss:
7 Comments
Permanent Link:
Save
Category:
Web
Post to:
del.icio.us
The default WordPress search engine barely qualifies as a search engine. It's results are not that relevant, the search page shows the actual blog entries instead of a list of links of resulting pages and the experience gets worse if the search query gets the least bit creative.
I think everyone should deprecate the WordPress search engine and move to Google Custom Search. There is simply no comparison. You can see the search results for AJAX on my website.
How-to for Google Custom Search Implementation in WordPress
Having recently implemented it on my site I don't think it gets much better than this. Implementing it in WordPress is trivial and the results are of the highest quality.
- Head on over to http://www.google.com/cse/ and register for an account. Follow the prompts all the way until asked to select the kind of layout/code options.
- The best Google Custom Search configuration I think is to select the iframe option with advertisements placed on the right. Secondly, you will want to specify the search results url as something like http://yourdomain.com/search.php. More on that in a minute.

- Subsequently you will be shown two textarea's. The first one is the search box code which shows the input field where queries are entered. You can paste this code in your header or index template (header.tpl or index.tpl in the wp-content/theme/ directory) depending on where you want the box to show up.
- The second code box is for the search results page. To display the Google Custom Search results on a fresh page, create a file called search.php in the root of your web directory (this corresponds to the results url you entered above). Within this page you should paste both code snippets. The Google Custom Search box code will display the search box to the users once again so they can see their own query. The Custom Search results code will display the actual results below the box. This is what your search.php will look like:
PHP:
-
<?php
-
// these two lines get the theme page initialization code and header
-
require('./wp-blog-header.php');
-
get_header();
-
?>
-
-
<!-- Google CSE Search Box Begins -->
-
...
-
<!-- Google CSE Search Box Ends -->
-
-
<!-- Google Search Result Snippet Begins -->
-
...
-
<!-- Google Search Result Snippet Ends -->
-
-
<?php get_footer(); ?>
- That's it, you're done.
Your page won't be instantly indexed and may take a day or two, but that's a small price to pay. And if you show your 5-10 most recent blogs in the sidebar then you're good anyway because users can navigate directly.