Canonical tag for common header

Canonical tag for the common Header : The PHP Code

canonical tag

I worked on some site scripts written on PHP that have common header and footer. Common Header is used to apply same header on multiple pages, that you will have to write header just once and header data remain same on each page. For Example, if you input <link rel="canonical" href="" />   to common header it will show the same canonical tag on every page I create.

Canonical tag must be unique on each page. Common C tag on every page makes problems on SEO. For instance,  Zoomin Photography Club I have common header, so when I put the  tag   <link rel="canonical" href="" /> for Home page, It is right for the Homepage but not good for other pages. Because my other page such as explore shows the same tag that is <link rel="canonical" href="" />    but it should be <link rel=”canonical” href=”” />

A little Explanation:  You may visit a website from various domain addresses such as

If the content of the above URLs remain same, than Search engine may take the content as a duplication. When a search engine bots crawl your site, it fails to decide which page should be indexed. If the pages show the same content, the bot will assume one copy is the copy of other and throw a penalty. Using a  tag can solve this problem.

For Common Header: Some CMS contain common header, where implementation of a C tag is little much critical. If your script in PHP, and have a common header. Open Header file and paste the following

<link rel="canonical" href="https://<?php echo $_SERVER['HTTP_HOST']; ?><?php echo parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ); ?>" />

If your site has https than do not remove the https here. Otherwise use only http.Hope this tutorial will solve your problem to implementation of  C tag on the common header.The above php script to retrieve unique C tag on every page you create.This scripts is also applicable for the complex eCommerce site.If any problem arises, do not hesitate to put a comment.



©Shubho Salateen-2018


Like on Facebook