Run a free scan to test your PC's performance now.
 

How to Create an Autodiscovery Blog Search for Web Browser

Filed in: Web Development, Weblog, WordPress — October 30th, 2006

advertisement

Have you add LiewCF blog search to your web browser? Many readers are excited by the feature. I will show you how to create an auto discovery blog search for web browsers. WordPress used in this example.

Add LiewCF blog search to your browser
Add LiewCF blog search to your web browser (FireFox 2 in this example)

The OpenSearch technology

We are using OpenSearch technology for the auto discovery blog search. OpenSearch is a collection of simple formats for the sharing of search results. Currently, both Internet Explorer 7 and Firefox 2 support this feature. Please refer to OpenSearch.org for technical documents.

Overview

It is easy to create an autodiscovery search for web browsers. We need to create a simple xml file and add a line of code into your web page's header. That's all. Read on for details.

Note: This tutorial is for WordPRess blog. You might need to modify the code to work with your blogging platform.

Creating OpenSearch XML file

Now, we create a XML file which would be read and added into user's web browsers.

  1. Create a new plain text file
  2. Paste the following lines of code into it:
    XML:
    1. <?xml version="1.0"?>
    2. <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
    3.     <ShortName>YOUR_BLOG_NAME</ShortName>
    4.     <Description>YOUR_BLOG_DESCRIPTION</Description>
    5.     <Url type="text/html" template="http://YOUR_BLOG/PATH/index.php?s={searchTerms}" />
    6.     <LongName>YOUR_BLOG_LONG_NAME</LongName>
    7. </OpenSearchDescription>

  3. Replace these terms in the code with yours:
    • YOUR_BLOG_NAME -- the name of your blog
    • YOUR_BLOG_DESCRIPTION -- tell people about your blog
    • YOUR_BLOG/PATH -- your blog path
    • YOUR_BLOG_LONG_NAME -- a longer blog name
  4. Save the file as "myopensearch.xml"
  5. Upload "myopensearch.xml" to your WordPress blog root.

Blog search auto discovery

In order to make web browsers auto discover our blog search, we need to add a <link/> tag into page header.

  1. Open "header.php" of your WordPress theme.
  2. Find:
    HTML:
    1. <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />[html]</li>
    2. <li>Add the following line of code immediately after the above line:
    3. [html]<link rel="search" title="LiewCF.com Tech Blog" href="http://www.liewcf.com/blog/liewcf-opensearch.xml" type="application/opensearchdescription+xml" />

  3. So, it will look like this:
    HTML:
    1. <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
    2. <link rel="search" title="YOUR_BLOG_NAME" href="http://YOUR_BLOG/PATH/myopensearch.xml" type="application/opensearchdescription+xml" />

  4. Save "header.php" and upload back to your WordPress theme folder.

You're done! Back to your blog and add the blog search to your web browser. :)
References: Heath Stewart's Blog and Mozilla Developer Center

Bonus: WordPress OpenSearch plugin -- add OpenSearch RSS feed functionality to a WordPress blog. (Does not include browser AutoDiscovery)

Bookmark and Share

Read also:

What do you think? 6 Responses to “How to Create an Autodiscovery Blog Search for Web Browser”

Comments Feed | TrackBack URL
  1. #1
    Ajay D'Souza Says:

    Thanks for the tutorial Liew. Will be adding the blog search to my blog as well now :)

  2. #2
    Techtites » Blog Archive » How to Create an Autodiscovery Blog Search for Web Browser Says:

    [...] Read the complete tutorial » [...]

  3. #3
    Adding OpenSearch to your WordPress Blog » Bill2me.com Says:

    [...] I was going to writeup a full ‘How to’ on this but there’s already a great one over at LiewCF so why re-invent the wheel. Check out Liew’s great post! [...]

  4. #4
    Michele Moore Says:

    Thanks so much for a great tutorial! I hate to ask a really dumb question, but for those of us who just follow you instructions because we have no idea what we’re doing…

    When I save the file as myopensearch.xml with Note Pad, what encoding do I use? UTF-8, Unicode? Does it make a difference?

    Thanks so much for helping to make Happiness more visible!

  5. #5
    LcF Says:

    @Michhele Moore: UTF-8 or Unicode doesn’t matter because the code is standard alphabet characters.

  6. #6
    AdzP.co.uk Says:

    [...] Note: I owe credit to LiewCF: How to Create an Autodiscovery Blog Search for Web Browser [...]

Comments are closed. Submit your comment here