Posted on

Search shortcode

Relevanssi adds a shortcode to help making links to search results. That way users can easily find more information about a given subject from your blog. The syntax is simple (just replace the angle brackets with square brackets):

<search>John Doe</search>

This will make the text John Doe a link to search results for John Doe. In case you want to link to some other search term than the anchor text (necessary in languages like Finnish), you can use:

<search term="John Doe">Mr. John Doe</search>

Now the search will be for John Doe, but the anchor says Mr. John Doe.

One more parameter: settingĀ <search phrase="on"> will wrap the search term in quotation marks, making it a phrase. This can be useful in some cases.

 

  • James

    Is there a way to show search terms like the shortcode does but in the template?
    I want to display the 2 most popular search terms and while I cant find a way to do this automatically, if I can just show two terms in my template file that would work.

  • There’s no automatic way to do it. Check the Relevanssi source code to see how the “User searches” page is made, you can see the MySQL code to get the most popular search terms.