Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to put canonical tag on wordpress category page?

Posted on 2011-09-09
11
Medium Priority
?
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

 
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Did you use a default hosting installation of wordpress with the intention of it being your actual site?  Maybe you’ve installed it as a Blog to your current site and recently converted it to be the main site and do away with the old .htm pages.  An…
WordPress has made it easy to create scalable sites based on their powerful CMS, but as great as WordPress is, there are some SEO issues that haven’t been addressed out of the box.  Fortunately these problems can be solved with a few plugins.  The f…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…

670 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