Wordpress (x)HTML Title Tweak
by David Dolphin on Oct.31, 2007, under Meh
Made a small tweak to my Wordpress theme, inspired by Gerard at Interweb World (whos blog I found via a Google search). I realised that if someone tagged a link of mine in del.icio.us, and then showed it in Facebook they would probably loose the context of the post because I display my blogname before the post name. This little tweak may also be useful for improving your blogs ratings when search engines (such as Google) are indexing your blog (which is called search engine optimisation, SEO).
I made an edit to the header of my current Wordpress theme Classic (a default in (I think) all installations). Login then go to Presentation » Theme Editor » Header (for the theme you want to edit). It might be an idea to backup the theme so that you have something if everything goes pear shaped (as it did for me the first few tries). I’m not sure if this will work for wordpress.com accounts, maybe, maybe not.
The code your looking for should be 7-10 lines down and read
<title><?php bloginfo(’name’); ?><?php wp_title(); ?></title>
I’ve changed it to:
<title><?php if (is_home()) {} else { wp_title(”); ?> — <? }; bloginfo(’name’); ?> — David Dolphins Blog</title>
This can be rewritten as
<title>
<?php
if (is_home()) { }
else {
wp_title(”);
?> — <?
};
bloginfo(’name’);
?>
– David Dolphins Blog
</title>
A quick run through:
<title>
<?php
Opens the Title and php tags, Title outside the php tage because it is an (x)HTML tag and is not to be interpreted as php. The title tag can also be echoed from inside the php tag, but I like to keep my php as clean as possible.
if (is_home()) { }
else {
If we’re looking at the homepage then do nothing, but if it’s not the homepage…
wp_title(”);
?> — <?
};
Print the article / blog post title, I use two apostrophes as a parameter because without them I get a Guillemet before the article title. Then close the php tag and print ‘ — ‘. I could also have echoed this but I was lazy. Echoing may improve speed (as I’m closing a php tag inside an if). Close the if.
bloginfo(’name’);
?>
Print the blog name, in this case “*Terms and Conditions apply” and then close the php tag.
– David Dolphins Blog
</title>
Print my custom text and then close the title tag. You may want to change “David Dolphin” to your own name.
