Select the proper code for your title tag

Depending on what template your start with and the purpose of your site, you may come across different WordPress variations for displaying the title tag. The following are examples:

Simple and most common:

<title><?php bloginfo('name'); ?> <?php wp_title(); ?></title>

More complex and better for SEO:

<title>
	<?php if (is_home()) : ?>
		<?php bloginfo('name'); ?> - <?php bloginfo('description'); ?>
	<?php else : ?>
		<?php wp_title('', 'false'); ?> - <?php bloginfo('name'); ?>		
	<?php endif; ?>
	</title>

If you’re concerned about search engine optimization, the simple way won’t provide you with the best result since your blog name will appear before your page/post title on every single page. The second method allows you to display your blog name and description on your home page, but inserts the title of your page/post before your blog name on all other pages.

However, this only works if your blog is your home page. If you’ve chosen to display a static page as your home page, you will notice that only the dash and blog description appears on the home page. This can easily fixed by using this instead:

<title>
	<?php if (is_front_page()) : ?>
		<?php bloginfo('name'); ?> - <?php bloginfo('description'); ?>
	<?php else : ?>
		<?php wp_title('', 'false'); ?> - <?php bloginfo('name'); ?>
	<?php endif; ?>
	</title>

Changing is_home() to is_front_page() will ensure that your blog name and description is displayed properly on your home page.

2 comments:

  1. This is a bit off subject, but necessary… your frames for WordPress are awesome. See what one can look like (look at my referenced site above; let me clarify that I am a user not designer so do not expect the Sistine ceiling). I have downloaded a couple hundred nice themes from other authors, but I always think that I should use your frame and build it right. (And usually regret not doing so.) Yeah it takes time but that is how artistry shines. I appreciate your work, others should too. Kudos.

    If I were asked, I’d suggest 4/5 column frame aimed at magazines. Usual header, a sub-header button/tab area laterally above the columns (maybe one above the header too, optional), option for 4 or 5 columns and optional side bar for embedded video and one for advertising. Just a thought. I know it would be a pleasure to use if you designed it. You could get a lot material for your posts out of that WP ‘zine frame…

    Thanks. Four times–once for each frame. Four thumbs up for the 3 column.

    1. Thanks for your words of praise DoktorThomas. I took a look at your site and it’s quite well done. Your suggestions are great ones and I’ll continue working on these. I originally created these for a WordPress class I was teaching, but I’ve been slowly refining them. I still have a few refinements to do, but those additional templates you suggested are also a good idea.

      Thanks again.

Comments are Closed.