When I last submitted Magazine Basic to the WordPress theme directory, I was told that they no longer allowed direct modification of certain elements within the header.php file. That meant I could no longer include a couple of conditional statements around the wp_title()
function to improve on its SEO. The new approach in the theme review guidelines is to filter the function, which is actually a more efficient way of doing it. Now all you have to do in your header.php file in include the wp_title()
function, the rest of the magic happens in your functions.php file.
add_filter( 'wp_title', 'filter_wp_title' ); /** * Filters the page title appropriately depending on the current page * * This function is attached to the 'wp_title' fiilter hook. * * @uses get_bloginfo() * @uses is_home() * @uses is_front_page() */ function filter_wp_title( $title ) { global $page, $paged; if ( is_feed() ) return $title; $site_description = get_bloginfo( 'description' ); $filtered_title = $title . get_bloginfo( 'name' ); $filtered_title .= ( ! empty( $site_description ) && ( is_home() || is_front_page() ) ) ? ' | ' . $site_description: ''; $filtered_title .= ( 2 <= $paged || 2 <= $page ) ? ' | ' . sprintf( __( 'Page %s' ), max( $paged, $page ) ) : ''; return $filtered_title; }
The above function will change the page title according to whichever page is currently being viewed. On your homepage, you'll see your site name and site description. All other pages/posts/categories will have their name first and then the site name. This helps improve your site's SEO by giving each page a unique title and is the first step in preparing your site for proper indexing by every popular search engine.
In order to make everything work correctly, make sure that the title tag in your header.php file looks like this: