LH Canonicaliser keeps the address bar on the page’s canonical URL. When a visitor reaches a page through a non-canonical address, for example one carrying tracking parameters or an old slug, it replaces the address bar and the current browser history entry with the canonical URL, without reloading or redirecting. Bookmarks, copied links and shares then use the canonical address.
The target URL is worked out in PHP from the same canonical URL WordPress or BuddyPress prints in the head, and other plugins can supply one for pages those do not cover.
Key features
- Uses the History API, so there is no extra request, reload or redirect.
- Query strings that carry meaning are never stripped: search terms, login redirects, comment moderation and reply links, previews, nonces and password reset links are kept. The list is filterable, so a site or plugin can add its own.
- The canonical link in the head is never changed.
- The URL fragment (
#section) is kept, and a canonical URL on another domain is ignored. - Only runs on front-end GET requests, never in embeds, previews or the Customizer.
- No settings. Behaviour is changed with filters.