Code

How to Fix Duplicate Title and Meta Tags When Spanning Multiple Home Pages in WordPress

This post describes how to fix duplicate meta and title tag content when spanning multiple home pages in WordPress. This isn’t a topic I normally cover here at www.iceflatline.com, but after searching for a solution to this problem for this site and continually encountering advice such as just add a plugin, I decided to post how I fixed this problem without encumbering my site with yet another WordPress plugin or other solutions.

The Problem

Like each post here at iceflatline.com, my index or main “home” page contains its own unique description and keywords meta tags and title tag content. WordPress allows me to determine the number of posts displayed on my home page (I typically choose five). Once this limit is reached, my WordPress theme automatically generates an “Older Entries” link at the bottom of the page, allowing the reader to navigate to a another page containing the previous five posts, and so on. While this is a helpful navigation feature for the reader, to a search engine like Google it’s another URL that contains the same meta and title tag content as that of the main home page. For example, I use the following content for my home page description and keywords meta tags:

Left unchanged, however, each Older Entries link will also contain the same description and keywords content. Consequently, tools like Google’s Webmaster Tools will complain that it has detected duplicate meta descriptions. This issue likely won’t prevent your site from appearing in search results, but paying attention to it can provide Google and other search engines with more information and help drive traffic to your site.

The Solution

To fix the problem of duplicate meta and title content I added a bit of PHP code to my theme’s header.php file. When a reader of iceflatline.com uses the Older Entries link to view a page containing its previous five posts, this code will automatically prepend or append a page number to the contents of these tags so that the metadata in each of these pages appears unique to the search engine. The page numbering starts with 2 and increments each time the reader navigates to a previous page.

    Duplicate Meta Tag Content

To eliminate duplicate description and keywords meta tag content, I added the following PHP code to my theme’s header.php file:

Now when someone clicks on Older Entries the description and keywords meta tag content will be prepended with a page number so that it looks like this:

If desired, the following variations of the code above will append the page numbers instead:

    Duplicate Title Tag Content

To eliminate duplicate title tag content, I appended the following PHP code to the tag’s existing contents in my theme’s header.php file:

Combined with the original code, the revised PHP code within the title tags now looks like this:

Now when someone clicks on Older Entries the title description will be appended with a page number so that it looks like this:

Conclusion
There ya have it. A bit PHP code and I fixed these nagging problems, and saved myself the hassle of having to update and manage yet another WordPress plugin or use some other solution that didn’t fully meet my needs.

13 comments How to Fix Duplicate Title and Meta Tags When Spanning Multiple Home Pages in WordPress

Luishi says:

Thank you I was looking for several months a way like this, because I don´t want to continue using All in one seo to avoid duplicated home pages which it was my problem in Google webmasters tools.

Awesome – been looking for this code for a while.. would of thought wordpress would auto solve pagination problems

iceflatline says:

Adrian, awesome; glad I could help.

tornadic says:

Really wished this worked for me but whenever I try to bookmark my wp themes front page I am getting duplicate titles. It appears like “SitenameSitename Description”.

I have read alot of articles and tried various scripts and just cannot seem to solve the problem. I am running Wp 3.3.1 and I too would really rather not use any plugins to solve it, any suggestions?

iceflatline says:

tornadic, sorry, I’m not really sure how to help.

CA-3 says:

@tornadic – try this, put it right below the tag:

– <?php bloginfo('description'); }
elseif ( is_category() ) { single_cat_title(); echo ' – ' ; bloginfo(‘name’); }
elseif (is_single() ) { single_post_title(); echo ' – ' ; bloginfo(‘name’); }
elseif (is_page() ) { single_post_title(); echo ' – ' ; bloginfo(‘name’); }
if ($paged

What it does is when you’re;
on the homepage – “Sitename – Description”
on single post – “Post Title – Sitename”
on single category – “Category – Sitename”
on single category page# – “Category – Sitename – Page#
and so on…

@iceflatline – Thanks for this tutorial. Exactly what i was looking for to fix the duplicate meta and title thingy GWebmaster is nagging me about. Also could you help me with the results page? When I hover on chrome’s tab, your site’s search title looks like this: “Search Results apache | iceflatline”. On my site, it’s “Sitename.com/?s=searchword”. Can you tell me what code to use? Thanks!

iceflatline says:

CA-3, thanks for helping out here.

Concerning the title issue, I added the following to my title tag code in the header of my theme:
[php]
<?php wp_title(‘ ‘);
if(wp_title(‘ ‘, false)){
echo ‘ | ‘;
}
echo bloginfo(‘name’);
[/php]

As a result, when someone is on home page they get “iceflatline”. On single posts they get “How To Fix Duplicate Title and Meta Tags When Spanning Multiple Home Pages In WordPress | iceflatline”. On a search result for “wordpress” they will see “Search Result wordpress | iceflatline”.

So, the entire title tag code looks like this now:

[php]
<title>
<?php wp_title(‘ ‘);
if(wp_title(‘ ‘, false)){
echo ‘ | ‘;
}
echo bloginfo(‘name’);
if ($paged < 2 ){
}else{
echo (‘ | ‘ . ‘Page ‘);
echo ($paged);
}
?>
</title>
[/php]

CA-3 says:

Thanks for the help, the code worked for my site but I seem to be having troubles on properly placing “bloginfo(‘description’);”

“< ?php wp_title(' '); echo ' – ' ; bloginfo('description');" resulted in displaying "Description – Sitename".

This line, added to my code, did the trick I wanted:
elseif (is_search() ) {echo('Search result: '); the_search_query(); echo ' – ' ; bloginfo(‘name’); }

Thanks again for your time, hope you feature more wordpress tricks in the future. =)

iceflatline says:

CA-3, awesome. Glad you got it worked out. Thanks for posting back.

network_j says:

2 if(wp_title(‘ ‘, false)){
3 echo ‘ | ‘;
4 }
5 echo bloginfo(‘name’);

Not sure I understand this part of the code. Is the if statement testing for a null wp_title? What I am getting for output is bloginfo(‘name’) bloginfo(‘description’) | bloginfo(‘name’). That’s why I’m asking about the the if statement.

I have a bloginfo(‘name’) in my General Settings. Why would I want it twice in the ?

kalyan says:

how about in blogger??

iceflatline says:

kalyan, I have no idea.

vipjatt says:

awesome thanks for share ,,

Leave a Reply

Your email address will not be published. Required fields are marked *