News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

[Solved] Canonical on products?

Started by Gipa, February 27, 2013, 22:21:35 PM

Previous topic - Next topic

Gipa

Is there any way to add canonical rel to the products?

I found a "VM add canonical"-plugin, but it was for VM1...

The best thing would be to be able to choose a canonical url for each product, but an automated way would also be fine. Any ideas?

:)

Gipa

I don't understand - this is a common issue, and I have found plenty of posts asking about this, but no answers...

When you place a product in more than one category in VM2, you WILL get duplicate content because each category placement creates its own url.
There has to be a solution for this? Or does all VM2 users just accept duplicate content...?

Removing the categories from the urls seems impossible - except if you use a 3rd party SEF component, and apparently these often break VM2.

But canonical would be the obvious solution for this problem. Does anybody have ANY idea how to do canonical urls on products?

Pleeeeeease!    :'(

PRO

vm2 has automatically added the canonical url since as long as I can remember

&&

product->url    should ALWAYS be the canonical url.

what version on 2.00 are you using? & do you have template overrides?



Gipa

I know, but each url just points back to itself.        :o

I checked a product that is placed in two different categories, so it has two different urls. When I visit url1, it has url1 as canonical. When I visit url2, it has url2 as canonical.
That is just crazy...

I need Virtuemart (or better yet, myself) to choose one url for each product and have that as canonical rel for all instances of the product...

I use VM 2.0.18a and Joomla 2.5.9. I use Beez2 as template and have made some adjustments to the template (also to VM2 template), but nothing that should be able to mess with canonical rel...

Gipa

#4
[EDIT: SEE FINAL SOLUTION IN A LATER POST IN THIS THREAD!]

Alright then!
I finally became desperate enough to spend hours trying to create my own solution (I'm not a programmer, so it took some trial and error   ;)  ).
This might not be the easiest solution, but it works...!     8)

If anyone else needs to create canonical urls for products:

1: I created a custom field called "Canonical url" - just a string. Set it as hidden (don't know if this is necessary) and gave it "canonical" as position.

2: In /components/com_virtuemart/views/productdetails/view.html.php on line 216 I commented out:
$document->addHeadLink(JRoute::_($product->canonical, true, -1), 'canonical', 'rel', '');
(This is the code that gives you the page's own url as canonical url. BE AWARE! THIS FILE WILL PROBABLY BE OVERWRITTEN WHEN YOU UPDATE VM2 - REMEMBER TO MAKE THE CHANGE AGAIN, OR YOU WILL HAVE 2 CANONICALS! I don't know how to copy this to my own template so it is not overwritten...)

3: Copied the file /components/com_virtuemart/views/productdetails/tmpl/default.php and placed it in /templates/beez_20/html/com_virtuemart/productdetails (this is the template I use - copying the file to this place ensures that your changes are not overwritten when you update VM2 later on.)
I then inserted this code at line 56. (It shouldn't matter where in the file you place it.)

<?php // Canonical url if it is entered
   if (!empty($this->product->customfieldsSorted['canonical'])) {
   ?>
   <div class="product-fields">
   <?php
   $custom_title = null ;
   foreach ($this->product->customfieldsSorted['canonical'] as $field){
      if ($field->display) {
         $custom_title = $field->custom_title;
       $document->addHeadLink(JRoute::_('http://domain.dk'.$field->display, true, -1), 'canonical', 'rel', '');
      }
   } ?>
   </div>
<?php } // Canonical end ?>


(Remember to change the domain.)

Now you can use the custom field on products that need a canonical url.     8)

I set it up so in the custom field you just enter the part after http://domain.dk - but if you want to enter the entire url in the field, you can change:
$document->addHeadLink(JRoute::_('http://domain.dk'.$field->display, true, -1), 'canonical', 'rel', '');
to:
$document->addHeadLink(JRoute::_($field->display, true, -1), 'canonical', 'rel', '');


8)

Peter Pillen

This is a labour intensive solution because you still have the categories. With your code you would need a different template for each override. And I now get why you want to remove the categories from the urls.

PS: I do support your point of view concerning canonical urls pointing to themselves. I also started a topic about that some time ago. And I know the problem is underrated. It is still on my todo list as "unsolved"  ::)

Gipa

Yes, it's very labour intensive. I have around 1,300 products and maybe half of them are in more than one category, so I have to go through each of these, add the custom field "canonical" and enter the canonical url for that product. It'll take forever...
But it has to be done - I can't have 5 urls pointing to the same content...

What do you mean "need a different template for each override"?

The PS: It shouldn't be a problem that some pages link back to themselves - my solution does that too - as long as the other urls with the same content point to that same page in stead of all pointing to themselves.

By the way: You seem to have good knowledge of VM2. Do you know how I can make a copy of /components/com_virtuemart/views/productdetails/view.html.php so it isn't overwritten the next time I update VM2?


:)     Rie

Peter Pillen

I don't think that file can be overridden in any way. It's more a "technical view" file than an actual view. I haven't tried yet, but i'm pretty sure it won't work.

QuoteWhat do you mean "need a different template for each override"?
correction... I didn't express myself correctly... you would a different template override for each category. But actually... if your site is still in development, put the canonical issue on a later todo list. Because I think some developpers will be improving that soon. In which case this problem could be solved in the near future.

Gipa

Oh, you mean if I want to make canonical in category view...!
No, I just need a canonical rel for the product pages, so editing the product detail view will do.

The site is a development site right now, but I hope to launch within a week or two, so they probably won't be done by then. Would really be nice though...!     :)
(But I mainly need to fix urls, 301 redirects and internal links in the content, and then I'm just about done. So I can't really do anything else in the meantime...)


:)    Rie

PRO

Quote from: Gipa on March 02, 2013, 22:36:42 PM
I know, but each url just points back to itself.        :o



then something is wrong with YOUR site or setup.

This is NOT how the canonical works.

Canonical url is  always the LOWEST category ID url that the product is in.

&&& on top of that, if the  category template uses $product->product_url    for the url built,

EVERY url should always be the canonical



Peter Pillen

#10
I just doublechecked everything again at my side. Seems that the canonicals are working since 2.0.18b. I had the same issue with canonicals a while back. Apparantly it must have been changed during 2.0.18a to 2.0.18b  :o

It does point to one of the child categories now.

radu4us

Does anyone know what do I need to modify and where in order for canonical to work in 2.0.18a?

I don't want to update to 18b or 18c yet.

PRO

Quote from: radu4us on March 03, 2013, 21:02:15 PM
Does anyone know what do I need to modify and where in order for canonical to work in 2.0.18a?

I don't want to update to 18b or 18c yet.

we dont know how you have the problem.

it could be in your version, or your template

Gipa

I went to http://virtuemart.net/downloads to download 2.0.18b to see if that helped, but 2.0.18a is still the latest version for download?
Where do I find the b version - and is it stable/ready for production site, since it isn't on the official download-site?

"if the  category template uses $product->product_url    for the url built" - I'm not sure what you mean? Could you explain/rephrase please?


:)     Rie

Gipa

Ok, I found it and upgraded to 2.0.18c. Had an error with the aio package, but the core installed fine.
Still have the same problem, though... Each product still has a canonical back to itself in stead of pointing to the category with the lowest id.

Any idea how I can find out what is wrong?
This is a major problem and it's keeping me from launching the site...     :'(