wp_get_canonical_url()
Returns the canonical URL for a post.
When the post is the same as the current requested page the function will handle the pagination arguments too.
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
Return
String|false
. The canonical URL. False if the post does not exist or has not been published yet.
Usage
wp_get_canonical_url( $post );
- $post(int|WP_Post)
- Post ID or object.
Default: global $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. |