Basics SEO for WordPress

A Basics SEO for WordPress should make that the content you publish don’t vanish in the wwwild… so let’s garnish some meta tags for diner. Let’s deal first with the title tag and then see what the description in the belly.

Title Tag

* Print the <title> tag based on what is being viewed.
if ( ! function_exists( 'basics_title' ) ) :
    function basics_title() {
        global $page, $paged;
        wp_title( '|', true, 'right' );
        // Add the blog name.
        bloginfo( 'name' );
        // Add the blog description for the home/front page.
        $site_description = get_bloginfo( 'description', 'display' );
        if ( $site_description && ( is_home() || is_front_page() ) )
            echo " | $site_description";
        // Add a page number if necessary:
        if ( $paged >= 2 || $page >= 2 )
            echo ' | ' . sprintf( __( 'Page %s', 'basics' ), max( $paged, $page ) );

This function called in the header.php file is supposed to print le blog’s name and the blog’s description when displaying de home page, like this :

<title>WordPress Basics | A Hard Rock-solid Theme based on HTML5 Boilerplate «For Those About to Rock» with WordPress</title>

When we are displaying a single page, the title tag is garnished with the title of the post, following by the blog’s name :

<title>Using the Basics grid | WordPress Basics</title>

Description Tag

Like the Title Meta Tag, the description one need to present two faces: one when come the home page, and another when a single page shows the tip of his nose.

* Print the <meta description> of the web page
if ( ! function_exists( 'basics_description' ) ) :
    function basics_description() {
        global $post;
        if ( is_home() || is_front_page() ) {
            $description = get_bloginfo( 'description', 'display' );
        } else if ( '' !== $post->post_excerpt ) {
            $basics_description = strip_tags( $post->post_excerpt );
        } else {
            $description = wp_html_excerpt( $post->post_content, 200 );
    return $description;

According to the code above, the meta description will be filled with the standard description you gave when you installed WordPress (The Slogan). Otherwise, there are two other solutions: one path is to fill this tag with the post_excerpt() when available, the other is to give the description the 200 firsts words founded in the page. And Voilà !

The last way you may prefer, is not to fill the description tag at all: Google would find its way one way or another (Blondie’s style) 😉