rel_canonical() WordPress Function
The rel_canonical() function is a powerful tool for managing your Wordpress site's SEO. This function allows you to specify the canonical URL for your site, which can help you avoid duplicate content issues with search engines. You can use the rel_canonical() function to specify the canonical URL for your entire site, or for specific pages or posts.
rel_canonical() #
Outputs rel=canonical for singular queries.
Source
File: wp-includes/link-template.php
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"; } }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
4.6.0 | Adjusted to use wp_get_canonical_url() . |
2.9.0 | Introduced. |