Universal PHP Code for Canonical URLS

Written on 19/05/2020

Universal PHP Code for Canonical URLS

A canonical link element is an HTML element that helps webmasters prevent duplicate content issues in search engine optimization by specifying the “canonical” or “preferred” version of a web page.

A major problem for search engines is to determine the original source for documents that are available on multiple URLs. Content duplication can happen in many ways, including:

  • Duplication due to GET-parameters
  • Duplication with multiple URLs due to CMS
  • Duplication due to accessibility on different hosts/protocols
  • Duplication due to print versions of websites

Duplicate content issues occur when the same content is accessible from multiple URLs.

 

Below is the code that you need to add within the head of your theme template:

A major problem for search engines is to determine the original source for documents that are available on multiple URLs. Content duplication can happen in many ways, including:[3] Duplication due to GET-parameters Duplication with multiple URLs due to CMS Duplication due to accessibility on different hosts/protocols Duplication due to print versions of websites Duplicate content issues occur when the same content is accessible from multiple URLs.

canonical

Obviously you will need to replace bybe.net with your own domain.

Adding canonical Links in WordPress

Below are a few easy steps that will have you up and running with WordPress canonical URLS in no time at all, and without a plugin.

  1. Login to WordPress
  2. Hover over Appearance
  3. Click Editor
  4. Find Theme Header (header.php)
  5. Add the Universal PHP Code for Canonical URLS found above within the HEAD section of your theme header file.

test here https://seositecheckup.com/tools/url-canonicalization-test