WordPress Template Building Resources Part 2

Meta Tags

WordPress does not include meta tags such as description and keywords in a default installation, you can add them to your template using the following code.

<meta name="description" content="<?php if ( is_single() ) {
        single_post_title('', true); 
    } else {
        bloginfo('name'); echo " : "; bloginfo('description');
    }
    ?>" />

This will add a description meta tag with the post title if the page is displaying a single post and the site name and description otherwise. If you prefer you can make the single post show the excerpt instead of the post title (probably more useful as the post title is likely to be the page title).

<meta name="description" content="<?php if ( is_single() ) {
        the_excerpt();
    } else {
        bloginfo('name'); echo " : "; bloginfo('description');
    }
    ?>" />

Further Reading

Published by

Mark Taylor

Web developer, based in Bourne, Lincolnshire, UK. builder of web applications, ASP.NET, Web Standards HTML, CSS & JavaScript. SQL Server & MySQL DB developer.

Leave a Reply

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