Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to put canonical tag on wordpress category page?

Posted on 2011-09-09
11
Medium Priority
?
270 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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
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
 
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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
If you are looking for plug-ins to add functions to your WordPress small business web site, take some time to read though this comprehensive list.  These are all the plugins I use for my customers WordPress web sites, as well as my own.  Be sure to …
This video teaches users how to migrate an existing Wordpress website to a new domain.
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
Suggested Courses

879 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