Welcome Guest, Not a member yet? Register   Sign In
Canonical Tag set
#1

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?
Reply
#2

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/h...urrent_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.
Reply
#3

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/';
Reply




Theme © iAndrew 2016 - Forum software by © MyBB