Automatic SEO Titles for All Your Pages
52The title of your page (The few words in the very top bar of your browser window) is arguably the most important thing search engines look at as they decide where to rank your page.
Most themes come with a very basic title set up; the name of your post and the name of the blog. It works well enough on regular post pages, but what about search pages, archives, 404s and all the others?
And some of these will be much more useful to your readers as well. We all know how helpful it is to open up 6 different tabs on one website only to find that they all start with the site’s name. Doesn’t help you keep track of all the pages you’ve opened very much.
The code below can be copied and pasted directly into your blog to create different titles for all the different types of page.
The New Titles
Below I have listed the new formats the titles will take for each of your pages (The actual title used on the page starts after the – ).
- Home Page – Blog Name | Blog Description
- Search Results – Search Results for search terms – 11 Articles | Blog Name
- 404 (Error) Page – Blog Name | 404 Nothing Found
- Author Archives – Blog Name | Author Archives
- Single Post – Post Name | Category Name | Blog Name
- Page – Page Name | Blog Name
- Category Page – Category Name | Category Description | Blog Name
- Monthly Archive – Blog Name | Archive | Month, Year
- Day Archive – Blog Name | Archive | Month Day, Year
- Tag – Tag Name | Blog name
How to Add To Your Blog
Open your theme’s header.php file and look for the line starting with .
In the default theme, it will look like this:
<title><?php wp_title('«', true, 'right'); ?> <?php bloginfo('name'); ?></title> |
Now delete this line and replace it with the following:
<title> <?php if ( is_home() ) { ?><? bloginfo('name'); ?> | <?php bloginfo('description'); ?><?php } ?> <?php if ( is_search() ) { ?>Search Results for <?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); echo $key; _e(' — '); echo $count . ' '; _e('articles'); wp_reset_query(); ?><?php } ?> <?php if ( is_404() ) { ?><? bloginfo('name'); ?> | 404 Nothing Found<?php } ?> <?php if ( is_author() ) { ?><? bloginfo('name'); ?> | Author Archives<?php } ?> <?php if ( is_single() ) { ?><?php wp_title(''); ?> | <?php $category = get_the_category(); echo $category[0]->cat_name; ?> | <? bloginfo('name'); ?><?php } ?> <?php if ( is_page() ) { ?><? bloginfo('name'); ?> | <?php $category = get_the_category(); echo $category[0]->cat_name; ?>|<?php wp_title(''); ?><?php } ?> <?php if ( is_category() ) { ?><?php single_cat_title(); ?> | <?php $category = get_the_category(); echo $category[0]->category_description; ?> | <? bloginfo('name'); ?><?php } ?> <?php if ( is_month() ) { ?><? bloginfo('name'); ?> | Archive | <?php the_time('F, Y'); ?><?php } ?> <?php if ( is_day() ) { ?><? bloginfo('name'); ?> | Archive | <?php the_time('F j, Y'); ?><?php } ?> <?php if (function_exists('is_tag')) { if ( is_tag() ) { ?><?php single_tag_title("", true); } } ?> | <? bloginfo('name'); ?> </title> |
For anyone who has meddled with their theme’s code a little before, you will see that the code above is (for the most part) fairly simple. You can chop and change as you like if a different style of title would suit your blog better.
What do you do for the titles on your blog? There are some great plugins out there to let you specify custom titles for each post, but is that too much hassle to update regularly?
WordPress Hacks Series: The code in these posts was written entirely by Milo, a web designer from Oxford, Britain. Check out her website for free WordPress themes and her blog, or follow her on Twitter!
Enjoy this post? You should follow me on Twitter!
frekaing awesome!
Wonderful article and thanks a ton for sharing the code…. This should make a lot on my blog simpler and interesting.
I’m definitely too lazy to write custom post titles for every one of my posts – but I also hate having that huge block of php in my header.php file. I much prefer to wrap it in a function and put it in functions.php – then you can keep your header nice and tidy, while maintaining your functionality. Either way, definitely a good skill to remember.
For the lazy folks you can also install the Platinum SEO Plugin: :)
http://techblissonline.com/platinum-seo-pack/
For those who don’t want to go into their theme files, there’s also the All-in-One-SEO Pack (http://wordpress.org/extend/plugins/all-in-one-seo-pack/), which does the exact same thing. I think it’s the more popular plugin compared to the Platinum SEO plugin, and it’s one that I use on every WordPress website that I build.
Thanks, Michael! I don’t use categories and I wanted the verbiage in the bar to be consistent from page to page, so here’s the code I’ve added, modeled after yours:
|
| Search Results for post_count; _e(”); echo $key; _e(‘ — ‘); echo $count . ‘ ‘; _e(‘articles’); wp_reset_query(); ?>
| 404 Nothing Found
| Author Archives
|
|
| Archive |
| Archive |
|
I’m wondering if it would shave a hair off a microsecond to replace each instance of with as you suggested in your post 13 tags to delete from your theme. What do you think?
Hmm … my code didn’t all show up … the perversities of trying to put code in a comment. :-/
Hi Michael, amazing trick, but I have a problem and although I modified the code can not resolve, because in the test blog when the blog on the cover, the structure of titles is: Blog Name | Description | Blog Name again, repeating the name of the blog at the end, I hope to help pruning, otherwise everything works perfectly.
Greetings
Awesome trick!
Just a question, why separating each line of php like this instead of writing one big block of code – I find it more readable…
Cheers
This post is broken in Opera. ;-)
Right near the end, there’s “look for the line starting with.” I suspect that you used actual greater-than/less-than instead of > and <.
Just thought you should know.
Now to the real purpose of commenting– to let you know that this was a great trick! Having every page start with the blog name sucks. I have to admit, I haven’t implemented this just yet, but it’s on my to-do!
SEO is very important part of every site which wants to gain visitors from search engines. And as one of most important seo on-page customizations are titles. Surely, this is very useful post, as in this case there is no need for plugin installation.
Isn´t there something called All in one SEO pack which does quite a good job? I don’t know what it does with 404 and search results but I don’t think you want those indexed in Google at all…
You might also wanna check that out, it’s a great plugin!
thanks for the code..
you have missed to put php in some calls to bloginfo.. ppl who doesnt know abt php wont be able to use ur code..
I like using a CMS that turns the page’s heder into the title with the previous title appended and the site’s name on the very right like this:
some specific page :: some group :: some website title
Good advice with the WordPress Title. I use the SEO Pack plug-in ( Like Bfri Commented ) that also makes the titles more search engine friendly and customisable. The SEO Pack also adds ‘No Follow No Index’ Meta tags to pages like 404 and archives etc.
v.nice tweak, we use the all in one SEO plugin for wordpress. Like somebody has already mentioned it’s so easy to forget or become lazy.
you don’t have to do anything manual now …. lots of SEO plugins are available now
Though you can do it all through plugin but loved to learn the codes from here.
I can see advantages to each method – the SEO plugin and the manual coding. The nice thing about the plugin is that it wouldn’t matter what blog theme you are using. However, with the manual coding, you can tweak things just the way you want them.
Why not use special plugins? AIOS as example, this very usefull than raw code)
futurit’s Latest Post: Helvetica World Fonts by Max Miedinger
Thanks a lot for this!
It’s of great use.
Thanks, but I have a problem!
– The blog title get’s added at the end of each title, even though it doesnt say in the code.
Why??
How do I get rid of it?
Thanks again!!
Edit: Sorry, problem solved!!
Seems like there is a little error in your last line?
I think the very last “blog title” was added to them all??
At least that happened to me..
that’s a great and easy seo tip, thanks for sharing!
As I see it the main goal and the main point of not using a plugin like AIOSEO Pack is too lower the strain plugins cause to the server. However there’s still a bunch of DB queries in that code. You could just swap half of them with static info, e.x. blog name, description.
I made with plugins.
what is better? use this tutorials or plugins? I hope you can answer.
Wow, very nice tutorial! thanks a lot!
wowww.. nice
I have bookmarks this tips.. thanks
wow!!!!!!! Great article and thanks
Hi, interesting post, i have been using AIO SEO for a while now and as far as my knowledge of seo permits me i have had possitive results, but thanks for the tip, i look forward to reading more of your posts. thanks
beautifull…. now my blog very SEO friendly after i try it in my blog :)
regard,
Creating descriptive titles is really important. Not only for search engines but also to users. It is important because it let the user know where it is in the website. Nice article.
Most of the time, title is the first and primary focus of the viewers. If it is interesting to them, they will surely read the entire content.
Great Tutorial..thankz
Could you please also provide the hack for META title,desc,and keyword without using plugin..i need the right code because when i tried.it always failed..
thx
Nice Tutorial !!
This is some great information that I can definitely use. Thanks for the awesome and useful posts.
Thank you sharing your information this useful information..i like this blog..
All Articles In One Place
This is so nice. I like it a lot.I will write a custom essay
about you.
Thanks for the superb content listed throughout your site, this is a trivial question for your blog site subscribers. Who actually cited the following quotation? . . . .Nothing great was ever achieved without enthusiasm.
Oh! Really nice articles, it will help the floks alot…
But let me tell you a little something: Gone are the days when you simply start a blog and people come flocking by the millions. People need to be able to find you and no, they aren’t going to come looking.
muhaaaaaaaaaaaa!! great stuff!!!
Thanks a lot for this article! I got a lot to learn about WordPress more
I am so delighted that I discovered this weblog. Thank you for the information.You make a whole lot of valuable points in your post.Waiting for ur next post..
Free Wallpapers| Screen Savers
I think other site proprietors should take this web site as an model, very clean and excellent user friendly style and design, let alone the content. You’re an expert in this topic!
Wonderful blog, a treasure in my bookmarks :)!
But for some reason this doesn’t work in my theme, instead of giving me my sites title and description it gives me some php code (don’t think that’s especially SEO friendly ;) ). I have paste it in my themes header just as you described.
Some clues on what’s wrong?
I think the post is good for us.I have paste it in my themes header just as you described.
Waiting for ur next post..
Free Wallpapers| Screen Savers
thanks, it is works
The above article is indeed quite informative as it deals with SEO. Being an Seo developer by profession, the above post is quite helpful for me. Thanks for sharing.
thanks for your wonderful information, this is one of the best way for making automatic titles.
Thanks for useful information. I think his is one of the best way for making automatic titles.