wp_get_canonical_url()
Gets the canonical URL of a post.
For pagination pages, a separate link is created. For example, for the comment pagination page of a post, it will look like this: http://example.com/postname/comment-page-2.
Uses: get_permalink()
Used By: rel_canonical()
1 time — 0.000338 sec (fast) | 50000 times — 3.05 sec (fast) | PHP 7.0.8, WP 4.6
Hooks from the function
Returns
String|false. Canonical URL or false if the post does not exist or has not been published yet.
Usage
wp_get_canonical_url( $post );
- $post(integer/WP_Post)
- ID or post object.
Default: null (current post)
Examples
#1 Output the canonical URL of post 803
echo wp_get_canonical_url( 803 ); // outputs: http://example.com/post-name/
Changelog
| Since 4.6.0 | Introduced. |