Feb
15th
Sun
15th
Automatically Deal With Duplicate Content in WordPress
You can just place the following code into your functions.php file within your theme folder.
function set_canonical() {
if ( is_single() ) {
global $wp_query;
echo '<link rel="canonical" href="'.get_permalink($wp_query->post->ID).'"/>';
}
}
add_action('wp_head', 'set_canonical');
That’s it! Now if you go to any version of your post page, you will see the little link on the top of the page publicly telling bots that the preferred version of the page is the permalink version. Take that duplicate contents!