Solved

how to put canonical tag on wordpress category page?

Posted on 2011-09-09
11
256 Views
Last Modified: 2012-06-27
Hey,

does anybody know how to put a canonical tag on wordpress blog category page?

currently the urls are like below, which is creating a duplicate content issues in webmaster tool...

site.com/blog/category/name1
site.com/blog/category/name2
and so on..

These all urls have same meta title and content, I think putting canonical on this page should resolve the problem?

Thanks
0
Comment
Question by:david_php
  • 6
  • 4
11 Comments
 
LVL 23

Expert Comment

by:jeremyjared74
ID: 36515164
To ensure that every page uses a unique URL, you should put this code after the opening <header> tag and before it closes:
<?php 
    if ( is_singular() ) 
    echo '<link rel="canonical" href="' . get_permalink() . '" />'; 
?>

Open in new window


There may be additional steps required depending on your permalink settings or the .htaccess file (if you;re on Linux Server, and it's being utilized).
0
 

Author Comment

by:david_php
ID: 36534221
sorry where exactly? in which file? and i think if i add this code manually, then it will be overwritten whenever blog is upgraded next time?
0
 
LVL 23

Expert Comment

by:jeremyjared74
ID: 36534582
It would go in the header.php file. Notice where I said

"To ensure that every page uses a unique URL, you should put this code after the opening <header> tag and before it closes:"


You can create a child theme to avoid it being over-written. To create a child theme you only need to create two files for now, the header.php file and a style.css file.

The style.css file would require this in the top of the file:
/* 
Theme Name: Conanical
Theme URI: http://www.yoursite.com/
Description: Not Required
Author: YOU
Author URI: Your URL
Template: twentyten
Version: 1.1
Tags: fixed
*/

/*Nothing required here, but is the optimal place for making edits to CSS so it doesn't get overwritten.*/

Open in new window


Just be sure to replace twentyten with the exact theme name for your current theme.

The header.php file would be your header.php copied and pasted into the new file. Then replace the code between the <title>THE CODE I SHOW ABOVE GOES HERE</title>. Save the file as header.php. Now create a folder and name it whatever. Place both the new files in this folder and upload it to the theme directory. Activate the theme. Now changes won't be overwritten.
0
 
LVL 23

Expert Comment

by:jeremyjared74
ID: 36534592
CORRECTION:


The code doesn't go in the title tags, it goes just after the closing </title> tag.
EXAMPLE:
<title>SOME TITLE STUFF HERE</title>
<?php 
    if ( is_singular() ) 
    echo '<link rel="canonical" href="' . get_permalink() . '" />'; 
?>

Open in new window

0
 

Author Comment

by:david_php
ID: 36543498
it din't work, any idea why?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 23

Expert Comment

by:jeremyjared74
ID: 36544289
How are your permalinks structured? If you go to Settings>Permalinks, what do you have them set to?
0
 

Author Comment

by:david_php
ID: 36547482
custom structure = /%postname%/
0
 
LVL 23

Expert Comment

by:jeremyjared74
ID: 36555105
I'm not sure why it's not working for you. Maybe you are better off going with a plug-in. All in One SEO is a very good Plug-in. It will help with more than your titles.
0
 
LVL 23

Expert Comment

by:jeremyjared74
ID: 36557153
Try this for the title tag in the header.php file:
<title><?php if (is_home() ) { 
  bloginfo( 'name' ); 
  }
elseif (is_category( ) ) { 
  single_cat_title( ) ; echo ' - ' ; 
  bloginfo( 'name' ) ; 
  }
elseif (is_single() ) { 
  single_post_title() ; 
  }
elseif (is_page( ) ) { 
  bloginfo('name' ) ; echo ' : ' ; 
  single_post_title() ; 
  } else { 
  wp_title( '' , true ); 
  } 
?></title>

Open in new window

0
 
LVL 31

Accepted Solution

by:
gwkg earned 500 total points
ID: 36582877
It didn't work because jeremy inadvertently used is_singular() instead of is_category().

That said, I don't think using a canonical link is a solution.  You need to make unique titles and descriptions for each category.

I prefer the SEO Plugin from Yoast.com http://yoast.com/wordpress/canonical/
0
 

Author Closing Comment

by:david_php
ID: 36947582
ok thanks
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Now that you've installed WordPress 2.9 (http://www.experts-exchange.com/articles/Web_Development/Blogs/WordPress/WordPress-2-9-What-to-Expect-When-Upgrading-to-WordPress-2-9.html?) on your site, you need to install some plugins to get the most out …
Like there are many different versions of Wordpress, there are also a handful of related side projects WordPress users should be familiar with.   All of these projects are open source and GPL licensed, which means there are few restrictions to us…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now