Home > Dev > WordPress SEO > Canonical URLs

Canonical URLs

This code adds canonical URLs to avoid duplicate content issues.

// Add this to your theme's functions.php file

function add_canonical_url() {
    if (is_singular()) {
        echo '<link rel="canonical" href="' . get_permalink() . '">';
    }
}
add_action('wp_head', 'add_canonical_url');
Back