Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/redirect canonical


Redirects incoming links to the proper URL based on the site url.

Search engines consider www.somedomain.com and somedomain.com to be two different URLs when they both go to the same location. This SEO enhancement prevents penalty for duplicate content by redirecting all incoming links to one or the other.

Prevents redirection for feeds, trackbacks, searches, comment popup, and admin URLs. Does not redirect on IIS, page/post previews, and on form data.

Will also attempt to find the correct link when a user enters a URL that does not exist based on exact WordPress query. Will instead try to parse the URL or query in an attempt to figure the correct page to go to.


<?php redirect_canonical$requested_url$do_redirect ); ?>


(string) (optional) Optional. The URL that was requested, used to figure if redirect is needed.
Default: null
(boolean) (optional) Optional. Redirect to the new URL.
Default: true

Return Values

Null, if redirect not needed. False, if redirect not needed or the string of the URL

Change Log

Since: 2.3

Source File

redirect_canonical() is located in wp-includes/canonical.php