VirtueMart Forum

VirtueMart 2 + 3 + 4 => Security (https) / Performance / SEO, SEF, URLs => Topic started by: Meton on November 07, 2015, 01:44:57 AM

Title: Setup canonical by default not like google wants it?
Post by: Meton on November 07, 2015, 01:44:57 AM
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
Title: Re: Setup canonical by default not like google wants it?
Post by: 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

Title: Re: Setup canonical by default not like google wants it?
Post by: Meton on November 08, 2015, 13:53:56 PM
Thx a mil pro!
Title: Re: Setup canonical by default not like google wants it?
Post by: Meton on November 08, 2015, 21:20:17 PM
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
Title: Re: Setup canonical by default not like google wants it?
Post by: 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', '');
            }
Title: Re: Setup canonical by default not like google wants it?
Post by: Meton on November 09, 2015, 14:55:40 PM
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!
Title: Re: Setup canonical by default not like google wants it?
Post by: Meton on November 09, 2015, 23:48:48 PM
Worked like a charm! I have gone live! Cheers m8
Title: Re: Setup canonical by default not like google wants it?
Post by: 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)


Title: Re: Setup canonical by default not like google wants it?
Post by: lindapowers on December 19, 2015, 12:05:22 PM
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
Title: Re: Setup canonical by default not like google wants it?
Post by: 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
Title: Re: Setup canonical by default not like google wants it?
Post by: lindapowers on December 19, 2015, 18:35:08 PM
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!
Title: Re: Setup canonical by default not like google wants it?
Post by: Milbo on January 04, 2016, 15:19:53 PM
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', '');
}