get_canonical_url
Filters the canonical URL for a post.
Usage
add_filter( 'get_canonical_url', 'wp_kama_get_canonical_url_filter', 10, 2 );
/**
* Function for `get_canonical_url` filter-hook.
*
* @param string $canonical_url The post's canonical URL.
* @param WP_Post $post Post object.
*
* @return string
*/
function wp_kama_get_canonical_url_filter( $canonical_url, $post ){
// filter...
return $canonical_url;
}
- $canonical_url(string)
- The post's canonical URL.
- $post(WP_Post)
- Post object.
Changelog
| Since 4.6.0 | Introduced. |
Where the hook is called
get_canonical_url
wp-includes/link-template.php 4106
return apply_filters( 'get_canonical_url', $canonical_url, $post );