Hi,
if you need to add Open Graph tags to your Cobalt records, just add somewhere after line 21 of components/com_cobalt/views/record/tmpl/default_record_article.php
<?php // OPEN GRAPH TAGS
//libxml_use_internal_errors(true); //Uncomment this line if you use a gallery field as record image.
//Get description text
if (isset($item->fields_by_id[6])): //Replace 6 with your description field ID
$descraw = substr($item->fields_by_id[6]->value, 0, 200).'...'; //Truncate text to 200 characters
$desc = strip_tags($descraw); //Strip text from xhtml markup
endif;
// Get thumbnail url
$dom = new DOMDocument;
$dom->loadHTML($item->fields_by_id[12]->result);// Replace 12 with your image/gallery ID
$x = new DOMXPath($dom);
foreach($x->query("//img") as $node)
// insert tags
$opengraph = '<meta property="og:title" content="'.$item->title.'"/>' ."\n";
$opengraph .= '<meta property="og:type" content="article"/>' ."\n";
$opengraph .= '<meta property="og:description" content="'.$desc.'"/>' ."\n";
$opengraph .= '<meta property="og:url" content=" http://mysite.com '.JRoute::_($item->url).'"/>' ."\n";
$opengraph .= '<meta property="og:image" content=" http://mysite.com '.$node->getAttribute("src").'"/>' ."\n";
$opengraph .= '<meta property="og:site_name" content="'."MY WEBSITE NAME".'"/>' ."\n";
$opengraph .= '<meta property="fb:admins" content="'."MY FACE BOOK DEVELOPER CODE".'"/>' ."\n"; // Not sure if you need a developer code. If not, comment this line out
$doc = JFactory::getDocument();
$doc->addCustomTag($opengraph);
?>
@Edit: Removed some redundant code and lines, added strip_tags to filter html.
Read also:
http://ogp.me/
Have fun!
Hi,
if you need to add Open Graph tags to your Cobalt records, just add somewhere after line 21 of components/com_cobalt/views/record/tmpl/default_record_article.php
@Edit: Removed some redundant code and lines, added strip_tags to filter html.
Read also:
http://ogp.me/
Have fun!