How to Add Canonical Urls to WordPress Blogs

It is very essential to add canonical urls to every WordPress blog web page to avoid duplicate content penalties by search engines. Canonical urls represent the permalink of the page and helps search engines identify and index the page, ignoring other parameters or mistyped urls loading similar content.

Add Canonical Urls

target canonical url1. WordPress AutoInsert – The latest versions of WordPress automatically adds the canonical url to the posts and pages only, but not to archives, tags, categories etc. So while for most blogs, it takes care of all your single posts and pages, it does not fix canonical url issues for your archives and other paginated categories/tags.

2. SEO WordPress plugins – ┬áPopular SEO WordPress plugins like All in One SEO or Yoast SEO have options to set canonical urls on all your blog pages and is the best way to add canonical urls in on click.

canonical urls by plugins

3. Premium WordPress Theme Frameworks – Some advanced theme frameworks like Thesis and Genesis have SEO options which allow auto setting of canonical urls, without use of above SEO plugins. However, they are paid WordPress themes, and most WordPress themes might not have options to set canonical urls automatically.

4. Manual Code Addition – If for some reason you wish to add canonical urls to all your single posts and pages manually, you can add the following code in the HEAD tags of your HTML code by editing header.php

<?php if (is_singular()) { ?>
<link rel="canonical" href="<?php the_permalink() ?>" />
<?php } ?>

Similarly if you want to add code manually to any page, you can simply add the canonical url on the page in the HEAD tags. For example, we have a problem using SEO plugins because we host WordPress in an alternative directory and the SEO plugins cannot create the correct url for the front page. So we directly add our main front page canonical url through a separate index.php file.