Setup canonical by default not like google wants it?

Started by Meton, November 07, 2015, 01:44:57 AM

Previous topic - Next topic

Meton

Hi Guys,

If you look at this page you can see that as it is the current canonical setup in virtuemart appears to be "not how google wants it". Any thoughts on this?

https://support.google.com/webmasters/answer/139066?hl=en

Referring to this part:
-----------------------------------------------
Avoid errors: use absolute paths rather than relative paths with the rel="canonical" link element.

Use this structure:  https://www.example.com/dresses/green/greendresss.html
Not this structure: /dresses/green/greendress.html).
-----------------------------------------------


Kind regards,

Meton
Joomla!         3.6.5
VirtueMart     3.0.18

PRO


Meton

Joomla!         3.6.5
VirtueMart     3.0.18

Meton

Quote from: PRO on November 07, 2015, 11:49:47 AM
I thought this was fixed.

The solutions is here
http://forum.virtuemart.net/index.php?topic=129421.0

Hi pro,

This worked in categoryview by using:

$document->addHeadLink( JRoute::_($link, true, -1) , 'canonical', 'rel', '' );


But in my productdetails page there is a totally different structure that i don't understand enough to dive in to this:

if($isCustomVariant !==false and !empty($isCustomVariant->usecanonical) and !empty($product->product_parent_id)){
$parent = $product_model ->getProduct($product->product_parent_id);
$document->addHeadLink($parent->canonical, 'canonical', 'rel', '');
} else {
$document->addHeadLink($product->canonical, 'canonical', 'rel', '');
}


Do you know how this is done?

Kind regards,

Meton
Joomla!         3.6.5
VirtueMart     3.0.18

PRO

// Set Canonic link
            if($isCustomVariant !==false and !empty($isCustomVariant->usecanonical) and !empty($product->product_parent_id)){
               $parent = $product_model ->getProduct($product->product_parent_id);
               $document->addHeadLink(JRoute::_($parent->canonical, true, -1), 'canonical', 'rel', '');
            } else {
               $document->addHeadLink(JRoute::_($product->canonical, true, -1), 'canonical', 'rel', '');
            }

Meton

Quote from: PRO on November 09, 2015, 13:31:47 PM
// Set Canonic link
            if($isCustomVariant !==false and !empty($isCustomVariant->usecanonical) and !empty($product->product_parent_id)){
               $parent = $product_model ->getProduct($product->product_parent_id);
               $document->addHeadLink(JRoute::_($parent->canonical, true, -1), 'canonical', 'rel', '');
            } else {
               $document->addHeadLink(JRoute::_($product->canonical, true, -1), 'canonical', 'rel', '');
            }

Ill give this a go when i get back home, thanks Pro!
Joomla!         3.6.5
VirtueMart     3.0.18

Meton

Joomla!         3.6.5
VirtueMart     3.0.18

alatak

Hello

I have fixed it, but a different way.
I did

    $document->addHeadLink(JUri::getInstance()->toString(array('scheme', 'host', 'port')).JRoute::_($product->canonical, FALSE), 'canonical', 'rel', '');


because the JRoute($link, false, -1)

-1 is for $ssl parameter.
If it is $ssl=-1 then the canonical URL will be http://dresses/green/greendress.html even if your website is in SSL (set in joomla)



lindapowers

Quote from: alatak on December 15, 2015, 14:31:06 PM
Hello

I have fixed it, but a different way.
I did

    $document->addHeadLink(JUri::getInstance()->toString(array('scheme', 'host', 'port')).JRoute::_($product->canonical, FALSE), 'canonical', 'rel', '');


because the JRoute($link, false, -1)

-1 is for $ssl parameter.
If it is $ssl=-1 then the canonical URL will be http://dresses/green/greendress.html even if your website is in SSL (set in joomla)




Can you please tell me file to make the modification? Is this in the router file? location?

Regards

GJC Web Design

If this is a product details page I assume she means here

// Set Canonic link
            if($isCustomVariant !==false and !empty($isCustomVariant->usecanonical) and !empty($product->product_parent_id)){
               $parent = $product_model ->getProduct($product->product_parent_id);
               $document->addHeadLink($parent->canonical, 'canonical', 'rel', '');
            } else {
               $document->addHeadLink($product->canonical, 'canonical', 'rel', '');
            }

components\com_virtuemart\views\productdetails\view.html.php ~ line 219
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

lindapowers

Quote from: GJC Web Design on December 19, 2015, 14:41:11 PM
If this is a product details page I assume she means here

// Set Canonic link
            if($isCustomVariant !==false and !empty($isCustomVariant->usecanonical) and !empty($product->product_parent_id)){
               $parent = $product_model ->getProduct($product->product_parent_id);
               $document->addHeadLink($parent->canonical, 'canonical', 'rel', '');
            } else {
               $document->addHeadLink($product->canonical, 'canonical', 'rel', '');
            }

components\com_virtuemart\views\productdetails\view.html.php ~ line 219

Thanks man!

Milbo

Latest SVN has already:


// Set Canonic link
if($isCustomVariant !==false and !empty($isCustomVariant->usecanonical) and !empty($product->product_parent_id)){
$parent = $product_model ->getProduct($product->product_parent_id);
$document->addHeadLink( JUri::getInstance()->toString(array('scheme', 'host', 'port')).JRoute::_($parent->canonical), 'canonical', 'rel', '');
} else {
$document->addHeadLink( JUri::getInstance()->toString(array('scheme', 'host', 'port')).JRoute::_($product->canonical), 'canonical', 'rel', '');
}
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/