Sunday 21 July 2013

Correct Facebook share thumbnail and description - Joomla 2.5 & Virtuemart 2.0

This is a great way to add Open Graph meta tags to the flypage of Virtuemart, to specify the image used by Facebook like, share, send, etc buttons 
I have made some little improvements to your code though, so that it will not be necessary to hard code the domain name of your site and also i added the og::site_name meta tag.
Also I wanted the generated html code to be valid (http://validator.w3.org/) so i had to use addCustomTag() instead of setMetaData() to generate "meta property" instead of "meta name" .

Code: 
$og_type = 'article';
$og_url = JURI::current();
$og_image =  JRoute::_(JURI::base().$this->product->images[0]->file_url);
$og_desc = $this->product->product_s_desc;
$og_title = $this->product->product_name;

$app =& JFactory::getApplication();
$og_sitename = $app->getCfg('sitename');

$doc = JFactory::getDocument();
$doc->addCustomTag('<meta property="og:type" content="article"/>');
$doc->addCustomTag('<meta property="og:url" content="'.$og_url.'"/>');
$doc->addCustomTag('<meta property="og:site_name" content="'.$og_sitename.'"/>');
$doc->addCustomTag('<meta property="og:image" content="'.$og_image.'"/>');
$doc->addCustomTag('<meta property="og:description" content="'.$og_desc.'"/>');
$doc->addCustomTag('<meta property="og:title" content="'.$og_title.'"/>');


This piece of code has to be inserted at the first lines of file "components/com_virtuemart/views/productdetails/tmpl/default.php" just after the line:

Code: 
defined('_JEXEC') or die('Restricted access');
It would be even better if you copy this file at your template directory (folder: templates/my_Joomla_template/html/com_virtuemart/productdetails/) so that it will not be modified by any Virtuemart upgrades.


Check this Change by link:
https://developers.facebook.com/tools/debug

No comments:

Post a Comment