Adding the canonical tag to your WordPress blog might be essential if you do not want search engines to see your content twice (= duplicate content) and thus giving you a penalty as such.
To add this tag, simply go to your theme’s folder and find header.php
. Now, add the following somewhere after <head>
but before </head>
<?php if ( is_singular() ) echo '<link rel="canonical" href="' . get_permalink() . '" />'; ?>
Clear your cache and see if this meta tag was added.
Since WordPress is constantly innovating and adding features to its core, this CMS now natively supports the rel="canonical"
link-tag. To request WordPress to add this tag to your website’s pages, you have to paste this code into functions.php
(found in your themes directory, such as wp-content/themes/YourTheme):
add_action( 'wp_head', 'rel_canonical' );
In case you want to specifically remove the canonical rel-tag in the <head>
of your WordPress blogposts and pages, you may choose to specifically disable the build-in rel_canonical()
function that WordPress offers:
remove_action( 'wp_head', 'rel_canonical' );
Hi!
I’m having trouble with the “canonical” tag for paging articles on the homepage. How can I use it for my pagination?
for example: https://tech24h.us/page/2
thanx for sharing a awesome article after reading this article i know how to add a canonical url in any blog thanx
Thanks for the awesome post. I learn new thing today.
thanx for sharing a awesome