VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: Genius WebDesign on November 03, 2014, 15:17:30 PM

Title: Setting meta title and meta description on VM frontpage
Post by: Genius WebDesign on November 03, 2014, 15:17:30 PM
Hi,

This is more an information than a question..

I found out that if you have your main page in Joomla set as Virtuemart frontpage, then the meta description is not pulled from the menu item parameters.
To fix this I simply edited the VM frontpage template override:
/templates/[my-template]/html/com_virtuemart/virtuemart/default.php

and added this code in the beginning:
$appmeta = JFactory::getApplication()->getMenu()->getActive();
$docmeta = JFactory::getDocument();
$docmeta->setTitle( $appmeta->params->get('page_title') );
$docmeta->setDescription( $appmeta->params->get('menu-meta_description') );


And now both the meta title and meta description stored in the menu item settings is in effect on the VM frontpage.
This is very useful for many reasons, but mainly because you now have perfect control of your meta data even on multi-language shops.
Title: Re: Setting meta title and meta description on VM frontpage
Post by: kkalkntar on July 20, 2017, 01:47:01 AM
I'd like to add my code for adding other meta tags like keywords, twitter cards and open graph cards. Hope someone finds it useful as I did with Genius WebDesign post  ;)

$appmeta = JFactory::getApplication()->getMenu()->getActive();
$docmeta = JFactory::getDocument();
$docmeta->setTitle( $appmeta->params->get('page_title') );
$docmeta->setDescription( $appmeta->params->get('menu-meta_description') );
$docmeta->setMetadata('keywords', $appmeta->params->get('menu-meta_keywords') );
$docmeta->setMetadata('twitter:card', 'summary' );
$docmeta->setMetadata('twitter:site', '@twitteraccount' );
$docmeta->setMetadata('twitter:title', $appmeta->params->get('page_title') );
$docmeta->setMetadata('twitter:description', $appmeta->params->get('menu-meta_description') );
$docmeta->setMetadata('twitter:image', 'http://www.domain.com/'.$this->product->images[0]->getFileUrlThumb() );
$docmeta->addCustomTag('<meta property="og:title" content="'.$appmeta->params->get('page_title').'"/>');
$docmeta->addCustomTag('<meta property="og:description" content="'.$appmeta->params->get('menu-meta_description').'"/>');
$docmeta->addCustomTag('<meta property="og:type" content="website"/>');
$menulink = JRoute::_($appmeta->link);
$docmeta->addCustomTag('<meta property="og:url" content="http://www.domain.com'. $menulink .'"/>');
$docmeta->addCustomTag('<meta property="og:image" content="http://www.domain.com/'.$this->product->images[0]->getFileUrlThumb().'"/>');


note: you may need to disallow the Twitterbot for your thumb images to display correctly on the twitter cards
Title: Re: Setting meta title and meta description on VM frontpage
Post by: Margriet on August 10, 2017, 10:49:35 AM
Why isn't the first code by default included in VM? I now changed category/default.php, because when you choose Top Level Category when you don't have a Top Level Category everything looks fine on the frontend, but only when you check source code you find that meta description is showing <meta name="description" content=".  Read more" />
This is not according to default Joomla behaviour. So it took me a few days to find out that it was caused by VM.