Get A Better WordPress Title In 30 Seconds!
Over the years there have been many attempts at improving the way WordPress displays your blog's page title. There are several plugins that let you modify the way your title is displayed and some that even let you specify a title for your posts.
I've tried several of these solutions and, honestly they have all been lacking in one way or another. I'm not going to run down a laundry list of what I don't like about each one, but no doubt many others have felt the same way about this situation as I have. So, I'm talking to you here.
I believe I have a better way. And it doesn't involve messy plugins with all sorts of other unnecessary features or typing in yet another field in your write post page.
This code will help you a lot with seo on your blog because it will put the important part of your title first and place your blogs name at the end of the title. Best of all, it's a completely fire and forget solution.
Here's the code you need.
[php]
< ?php
if (is_home()) {
?>
WordPress Themes, Plugins, Hints and Tips | Blog Strokes
< ?php
} else {
if(function_exists('UTW_ShowCurrentTagSet')) {
if (is_tag()) {
UTW_ShowCurrentTagSet('tagsettextonly');
echo ' | ';
bloginfo('name');
} else {
wp_title(' ');
if(wp_title(' ', false)) { echo ' | '; }
bloginfo('name');
}
}
}
?>
[/php]
Now all you have to do is open up your header.php for your theme and locate the <title> ... </title> section. Delete everything between those tags and copy/paste this code in it's place(be sure to click on the "Plaing Text" link before you copy).
This code has support for the Ultimate Tag Warrior Plugin which I use on all of my blogs, so it will also display your current tag set when you are on a tag page, but if you do not have UTW installed, it will skip that part and not cause any errors.
Let me know if you try this out. Let me know if you have any problems with it, and I'll be glad to help you out.
Trackback URL for this post:
Bookmark & Share: Click, Copy and Link:








Tax deduction tips... A tax
Tax deduction tips...
A tax is a financial charge or other levy imposed on an individual or a legal entity by a state or a functional equivalent of a state...
To get the individual posts
To get the individual posts title tags in I did a slight mod by adding . This seems to load the main page title well and the individual post titles well.
Pass Your Drug Test
Thanks for this solution.
Thanks for this solution. The default WP title definitely needs adjusting.
Yeah, Vlad you can do that
Yeah, Vlad you can do that easily. Just remove the bloginfo('name'): from everywhere but the main part for the home page.
Actually, in my code I hard wired the home page title with "WordPress Themes, Plugins, Hints and Tips | Blog Strokes". So to do what you want delete the two lines
if(wp_title(' ', false)) { echo ' | '; }
and
bloginfo('name');
both times they appear. This will leave you home page with whatever you type in the first section, and the rest of your pages with just the title for the page.
And yes, I suddenly received a serious traffic spike out of no where. When I went looking for where it came from it came from Stumble, and it all came to this post, so I figured you had stumbled me.
Thanks Dane. But I there was
Thanks Dane. But I there was some miscommunication on my part... I am thinking to use "bloginfo" only on the home page but for single posts I want to try only post's title.
I also answered your question on my blog about Stumble... Yes it was me. I hope you getting some visitors.
I also like the idea to play withe code instead of plugins. I just wish I can do what you do... Oh well, that's why this whole blogging thing is so cool- you can always learn from other bloggers.
Hi Vlad, The blog name is
Hi Vlad,
The blog name is inserted with this code
[php]
bloginfo('name');
[/php]
So to have it not show up on tag pages just remove it from the UTW section, and to have it not show up on other types of pages remove it from the else { } section.
If you wanted to add it back in to certain sections you could add another if() statement for those sections like
[php]
if (is_page()) {
wp_title(' ');
if(wp_title(' ', false)) { echo ' | '; }
bloginfo('name');
}
[/php]
The UTW code is there to output the tag set as the title on your UTW tag pages.
How come I am in pink? -
How come I am in pink?
- Fixed ;) I had turned it of for some troubleshooting. good catch, thanks. Dane -
Dane, I am guessing you are
Dane,
I am guessing you are in favor of adding the name of the blog to every post. However I would rather use code like this over the plugin.
What would I need to modify if I were to us this code but decided to not "brand" my every single post?
Also, what is UTW doint in the title?
Hey! Nice blog...I have had
Hey!
Nice blog...I have had good luck using the Utopia 1 plugin for my WP titles. I will give your code a go, Dane, and see if it improves my mood...
Peace,
Charlie~
:D
Post new comment