Canonical Tag set - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Canonical Tag set (/showthread.php?tid=67290) |
Canonical Tag set - micheal - 02-05-2017 Hi guys, I'm starting my 1st thread about where I have to add canonical tag in my site. I want to set Canonical Tag dynamically, but I don't know how to create the code/links and where I have to put!!! Anybody can help me? RE: Canonical Tag set - PaulD - 02-06-2017 I set it in a controller as a header variable: PHP Code: $header_data['canonical'] = 'home'; And in the view PHP Code: <?php if(!empty($canonical)) echo '<link rel="canonical" href="'.site_url($canonical).'">'; ?> However, I only use it for pages like the home page where it can have several routes into it. perhaps this could be made dynamic using current_url() as described here: https://www.codeigniter.com/user_guide/helpers/url_helper.html#current_url However I am not sure if current_url returns the used url or the full url. So not really an answer, just an idea about how it might be done. Best wishes, Paul. RE: Canonical Tag set - alpharay - 07-05-2018 I think you can just put this line in every php page <link rel="canonical" href="<?php echo current_url(); ?>"> as long as your config.php as the varaible $config['base_url'] = 'http://www.yourdomain.com/'; |