How to Use Canonical URLs in WordPress (without a plugin)?

4 replies
  • SEO
  • |
I understand how to use canonical urls on a static HTML based site, but I don't understand where to include these URLs on a WordPress based site.

They go in the head tags of the URLs of the pages with duplicate content... but I only have access to the files of my theme... so I'm a bit lost as to how to access the head tags for those URLs to input the code.
#canonical #plugin #urls #wordpress
  • Profile picture of the author phoenikz
    why avoid canonical plugin ?
    it is easier than coding the header.php
    Signature

    /looking for new business/

    {{ DiscussionBoard.errors[4655045].message }}
  • Profile picture of the author trentonlaura
    The less plugins the better unless I absolutely need it is my thought process.
    {{ DiscussionBoard.errors[4655755].message }}
  • Profile picture of the author sparrokei
    Originally Posted by trentonlaura View Post

    I understand how to use canonical urls on a static HTML based site, but I don't understand where to include these URLs on a WordPress based site.

    They go in the head tags of the URLs of the pages with duplicate content... but I only have access to the files of my theme... so I'm a bit lost as to how to access the head tags for those URLs to input the code.
    Place this in the header:

    <?php
    foreach((get_the_category()) as $cat);
    echo '<link rel="canonical" href="';
    if(is_home() || is_front_page()) {
    echo bloginfo('url');
    echo '/';
    } elseif(is_single() || is_page()) {
    echo the_permalink();
    } elseif(is_category()) {
    echo bloginfo('url');
    echo '/';
    echo $cat->category_nicename;
    echo '/';
    } elseif(is_tag()) {
    echo get_tag_link($tag_id);
    } else{}
    echo '">';
    ?>
    {{ DiscussionBoard.errors[4874536].message }}

Trending Topics