hostingarg Posted April 27, 2019 Share Posted April 27, 2019 Hello, I want to add: <link href="url visited" rel="canonical" /> in the header of the pages of my site web. Are there any hooks that I can use to add this line to all the pages of my site?I do not want to use {php} in smarty, for security.I already appreciate the help you can give me.regardsDiego 0 Quote Link to comment Share on other sites More sharing options...
bear Posted April 28, 2019 Share Posted April 28, 2019 Just add it into the header.tpl file? 0 Quote Link to comment Share on other sites More sharing options...
hostingarg Posted April 28, 2019 Author Share Posted April 28, 2019 The url is dinamic. I want not use php in .tpl For this reason I wanted to know if it could be implemented through a hook. Thanks 0 Quote Link to comment Share on other sites More sharing options...
string Posted April 28, 2019 Share Posted April 28, 2019 You can use the ClientAreaHeadOutput hook to add HTML into the header. 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted April 28, 2019 Share Posted April 28, 2019 Exactly, ClientAreaHeadOutput. <?php add_hook('ClientAreaHeadOutput', 1, function($vars) { $SystemURL = 'https://example.com'; $Page = 'whatever'; return <<<HTML <link rel="canonical" href="https://{$SystemURL}/{$Page}"/> HTML; }); 0 Quote Link to comment Share on other sites More sharing options...
bear Posted April 28, 2019 Share Posted April 28, 2019 (edited) 7 hours ago, Kian said: $Page = 'whatever'; That will deliver "whatever" to all the pages. How will it grab the page it's on, which is what he seems to be asking? EDIT: "filename" might do that. Edited April 28, 2019 by bear 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted April 28, 2019 Share Posted April 28, 2019 (edited) 49 minutes ago, bear said: That will deliver "whatever" to all the pages. How will it grab the page it's on, which is what he seems to be asking? EDIT: "filename" might do that. Nah, $vars['filename'] is the name of the tpl file that most of the times doesn't match page name. For example clientareahome refers to clientarea.php. Not to mention that ".php" is missing. Anyway I have intentionally avoided to specify $Page because it's more complicated than it seems. In fact there's no point in just placing the canonical URL that always matches current page name since Search Engines already know what's the URL to index. The use of canonical URL is to let them know on what URL of the page they must focus. There are some pages of WHMCS that are accessible from multiple URLs even though they provide the same content. That's duplicate content. Some other are exploitable if someone wants to hurt your indexing like in the following example: index.php?rp=/knowledgebase/1/real-news.html index.php?rp=/knowledgebase/1/real-news-yo.html index.php?rp=/knowledgebase/1/real-news-yo-yo.html index.php?rp=/knowledgebase/1/real-news-yo-yo-yo.html. 4 URLs for the same page 3 of which are fake. Incoming duplicate content penalties. That's where canonical URL helps you. Making it always equal to your domain followed by the query string is a waste of time. You can't trust the URL in the address bar. Edited April 28, 2019 by Kian 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.