{"id":445,"date":"2021-07-18T09:36:53","date_gmt":"2021-07-18T09:36:53","guid":{"rendered":"https:\/\/demo.wpartisan.net\/developmentsite\/how-to-add-canonical-urls-without-using-a-wordpress-plugin\/"},"modified":"2024-11-04T03:36:52","modified_gmt":"2024-11-04T03:36:52","slug":"how-to-add-canonical-urls-without-using-a-wordpress-plugin","status":"publish","type":"quick-tips","link":"https:\/\/demo.wpartisan.net\/developmentsite\/how-to-add-canonical-urls-without-using-a-wordpress-plugin\/","title":{"rendered":"How to add Canonical URLs without using a WordPress Plugin"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>What is a canonical URL?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A <strong>canonical URL<\/strong> is an HTML element that helps prevent duplicate content issues by telling search engines which version of a page to take into account when indexing your website.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Search engines face problems determining the original source for documents that are available on multiple URLs. You can help search engines using the rel=\u201dcanonical\u201d when you have pages with similar content.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Content duplication can happen in many ways, like:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Duplication due to GET-parameters( Ex: Search engines consider  https:\/\/wpartisan.net\/quick-tips\/how-to-add-canonical-urls-without-using-a-wordpress-plugin\/ and https:\/\/wpartisan.net\/quick-tips\/how-to-add-canonical-urls-without-using-a-wordpress-plugin\/?paramenter=1 entirely different URL. )<\/li>\n\n\n\n<li>Duplication due to with or without WWW in the URL.<\/li>\n\n\n\n<li>Duplication due to HTTP and HTTPS protocols( Ex: Search engines consider https:\/\/wpartisan.net\/quick-tips\/how-to-add-canonical-urls-without-using-a-wordpress-plugin\/ and http:\/\/wpartisan.net\/quick-tips\/how-to-add-canonical-urls-without-using-a-wordpress-plugin\/ entirely different URL. )<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>How to add in WordPress?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code \\&quot;wp-block-code\\&quot;\"><code lang=\"\\&quot;php\\&quot;\" class=\"language-\\&quot;php\\&quot;\">\/\/ You can add just editing your header.php file( inside &lt;head>&lt;\/head> section ) like:\n\n&lt;link rel=\"canonical\" href=\"https:\/\/wpartisan.net&lt;?php echo $_SERVER['REQUEST_URI'];?>\" \/>\n\n\/\/ You need to replace https:\/\/wpartisan.net with your domain name<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We can also add this using wp_head action hook like the one below:<\/p>\n\n\n\n<pre class=\"wp-block-code \\&quot;wp-block-code\\&quot;\"><code lang=\"\\&quot;php\\&quot;\" class=\"language-\\&quot;php\\&quot;\">add_action('wp_head', 'add_canonical');\nfunction add_canonical(){\necho '&lt;link rel=\"canonical\" href=\"https:\/\/wpartisan.net'.$_SERVER['REQUEST_URI'].'\" \/>';\n\/\/ You need to replace https:\/\/wpartisan.net with your domain name\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Before everything, we need to know what Canonical URL is, why a canonical URL is so important in SEO and why every page of your website should have a canonical URL.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}}},"tags":[17,39],"topics":[48,45],"class_list":["post-445","quick-tips","type-quick-tips","status-publish","hentry","tag-seo","tag-url","topics-html","topics-wordpress"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"WPArtisan","author_link":"https:\/\/demo.wpartisan.net\/developmentsite\/author\/developmentsiteauth\/"},"uagb_comment_info":0,"uagb_excerpt":"Before everything, we need to know what Canonical URL is, why a canonical URL is so important in SEO and why every page of your website should have a canonical URL.","_links":{"self":[{"href":"https:\/\/demo.wpartisan.net\/developmentsite\/wp-json\/wp\/v2\/quick-tips\/445","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/demo.wpartisan.net\/developmentsite\/wp-json\/wp\/v2\/quick-tips"}],"about":[{"href":"https:\/\/demo.wpartisan.net\/developmentsite\/wp-json\/wp\/v2\/types\/quick-tips"}],"author":[{"embeddable":true,"href":"https:\/\/demo.wpartisan.net\/developmentsite\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/demo.wpartisan.net\/developmentsite\/wp-json\/wp\/v2\/comments?post=445"}],"wp:attachment":[{"href":"https:\/\/demo.wpartisan.net\/developmentsite\/wp-json\/wp\/v2\/media?parent=445"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/demo.wpartisan.net\/developmentsite\/wp-json\/wp\/v2\/tags?post=445"},{"taxonomy":"topics","embeddable":true,"href":"https:\/\/demo.wpartisan.net\/developmentsite\/wp-json\/wp\/v2\/topics?post=445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}