Development, WordPress

Title Template Tags in WordPress

WordPress themers should be aware of all the different title template tags out there for properly calling page titles.  Not every function will work in all situations, so you have to think carefully about what to use and where.

Below is my synopsis of all the title template tags that WordPress has to offer:

Template Tag Proper Usage
wp_title() Used to display the page title within the HTML <title> tag.  This is typically altered for SEO purposes and should not be used to display page titles in the content area of a page.
the_title() Used within the loop to display the title of a post or page.  This function outputs the title immediately and is a wrapper function for get_the_title().
get_the_title() Used to fetch the title of a post or page.  Can be used outside the loop if is_singular() is true.  This is the only function on our list that doesn’t automatically print out the title to the page.  You can optionally provide an ID and get the page title for another page as well.
single_post_title() Used outside the loop to display the title for a single post or page.  This function also works when trying to display the title for the posts page when a user’s settings have designated a static page to display their blog.
single_cat_title() Used outside the loop on category pages to display the title for WordPress’s built-in categories.  It is now just a wrapper function for single_term_title() and will probably be depreciated in the future.
single_tag_title() Used outside the loop on tag pages to display the title for WordPress’s built-in tags. It is now just a wrapper function for single_term_title() and will probably be depreciated in the future.
single_term_title() Used outside the loop on taxonomy pages to display the title for any taxonomy.  This means that this function can be used instead of single_cat_title() and single_tag_title() and will also work for any custom taxonomies that have been defined.
single_month_title() Used outside the loop to display the title for date based archives.  The title will display the month and year and will require you to assign a prefix in order for it to appear correctly.  If a user is on a year based archive page, only the year will appear in the title.
post_type_archive_title() Used outside the loop to display the title on the main archives page (aka posts page) for custom post types ONLY.
the_search_query() Used outside the loop to display the search query.  Great to use in your search.php theme file, if you have one.

I would love to hear if and how you have been using these in your themes.

Standard

Leave a Reply

Your email address will not be published. Required fields are marked *