rel_canonical()

Outputs rel=canonical for singular queries.


Description Description


Source Source

File: wp-includes/link-template.php

3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
function rel_canonical() {
    if ( ! is_singular() ) {
        return;
    }
 
    $id = get_queried_object_id();
 
    if ( 0 === $id ) {
        return;
    }
 
    $url = wp_get_canonical_url( $id );
 
    if ( ! empty( $url ) ) {
        echo '<link rel="canonical" href="' . esc_url( $url ) . '" />' . "\n";
    }
}

Top ↑

Changelog Changelog

Changelog
Version Description
4.6.0 Adjusted to use wp_get_canonical_url().
2.9.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.