Jerome's Keywords - Displaying Post Keywords

Updated 13-Jan-2007 15:47

Normally you’ll want to display your post’s keywords (somtimes called “tags”). You can use

Tags: <?php the_post_keytags(); ?>

in any template file within the WordPress loop to display your keywords. This will output a list of comma-separated keywords that link back to your local keyword search. I use the above code for this site in practically every template file that displays posts.

You can change the appearance and behaviour of your keyword links by using the following optional parameters:

  • include_cats — set to true if you want post categories to be included in this list (the default is false)
  • local_search — determines what the keyword links to. You can use:
    • 'tag' — this is the default setting and creates links to your local keyword search. Links will be of the form siteurl/tag/keyword or ?tag=keyword, depending on your permalink settings. Doesn’t affect included categories.
    • 'search' — creates links to your normal WordPress search function for each keyword (pre-1.3 behaviour). Doesn’t affect included categories.
    • 'technorati' — links to that tag’s page on Technorati.
  • linktitle — specifies what text to put in the link title. The default is 'Search site for ' or 'Technorati tag page for ', depending on the previous option. This allows you to customize the output or write the title in another language besides English.

get_the_post_keytags() is a non-echoing version of this function.

the_post_keywords() is a simpler version that only outputs the keywords as plain text (i.e. no links). It only accepts the first parameter, include_cats. get_the_post_keywords() is the non-echoing version.