Advertisement:

Author Topic: Make canonical tags work  (Read 202 times)

bertrandg

  • Newbie
  • *
  • Posts: 29
Make canonical tags work
« on: March 08, 2018, 05:05:45 pm »
Hello,

Maybe this solution to make canonical tags work

check the head.php

Code: [Select]
<?php if( osc_get_canonical() != '' ) { ?>
  <link rel="canonical" href="<?php echo osc_get_canonical(); ?>"/>
<?php ?>

Replace

Code: [Select]
<link rel="canonical" href="<?php echo 'http://' $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>"/>
To test because I am an amateur. thank you for your return

m6mmi

  • Jr. Member
  • **
  • Posts: 59
Re: Make canonical tags work
« Reply #1 on: March 08, 2018, 05:20:59 pm »
Be careful with this one code, this code will make every filter for category into separate canonical url which is not correct and you will present duplicate urls/pages as unique.

bertrandg

  • Newbie
  • *
  • Posts: 29
Re: Make canonical tags work
« Reply #2 on: March 08, 2018, 07:24:12 pm »
Thank you for this analysis, do you think I should delete this code?

m6mmi

  • Jr. Member
  • **
  • Posts: 59
Re: Make canonical tags work
« Reply #3 on: March 09, 2018, 12:41:29 am »
Try it in you dev environment, if you have filters for categories (show as gallery, show as list, sort by recent, price, popular etc) and see if the canonical remains the same.
For category it should be and stay same whatever filter is being activated, if the canonical changes to filter url it´s not correct. <link rel="canonical" href="www.yourdomain.com/category-name " />

For my sites we went really basic way and hardcoded every category canonical, something like that. It´s definetly noobie way, but this way it works correctly (PS! We don´t use filters for categories.)

<?php if (osc_search_category_id()) { ?>
<?php if (Params::getParam('sCategory') == 'category-name') { ?>
<link rel="canonical" href="<?php echo osc_base_url();?>category-name" />
---------
elseif next category 2
-------
elseif next category 3
-------
<?php } ?>

bertrandg

  • Newbie
  • *
  • Posts: 29
Re: Make canonical tags work
« Reply #4 on: March 12, 2018, 03:23:00 pm »
Thanks,

I do not have a category filter because I do not have a price for my ads. I check my URLs are unique.