简体   繁体   中英

Joomla: Put Article Image in Head for Facebook

I would like to extract the article's intro image and insert it into the head for Facebook's og:image metadata. The problem is, I can't seem to get the correct information to fill in. Here's what I've tried...

<?php echo '<meta property="og:image" content="'.$images->image_fulltext.'">';
?>

<?php echo '<meta property="og:image" content="'.JLayoutHelper::render('joomla.content.intro_image', $this->item).'">';
?>

Also tried:

$doc = JFactory::getDocument();
$images = json_decode($this->item->images);
$fbimage = JURI::base() . $images->image_fulltext;
$doc->addCustomTag( '<meta property="og:image" content="' . $fbimage . '">' );

All I get out is <meta property="og:image" content="">

What do I need to to to grab the FQDN of either the article image or the intro image?

You can try below code -

$doc = JFactory::getDocument();
$doc->addCustomTag('<meta property="og:image" content="'. Juri::root() . $images->image_fulltext .'">');

Juri::root() returns the site URL. More detail about Juri Class

In order to get intro image or full image path you can refer this link .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM