When displaying an article with an image in the article itself, the og:image tag is NOT generated.
I have looked at the code and see that there is something not correct...
in file: ./html/com_content/article/default.php
the following code handles the og:image
- Code: Select all
if (version_compare( JVERSION, '1.8', 'ge' ) && isset($images->image_fulltext) and !empty($images->image_fulltext)) { $og_image = $uri->root() . htmlspecialchars($images->image_fulltext);
$pin_image = $uri->root() . htmlspecialchars($images->image_fulltext);
} else {
$og_image = '';
preg_match('/src="([^"]*)"/', $this->item->text, $matches);
if(isset($matches[0])) {
$pin_image = $uri->root() . substr($matches[0], 5,-1);
}
}[code]
it first looks for a fulltext image, if not found it goes to the else part where $og_image = set to '', but unlike $pin_image this variable is never set a value as you can see > resulting in NO og:image tag > resulting in facebook doing 'roulette' in choosing the article image :(
furthermore, setting $pin_image = $uri->root() . substr($matches[0], 5,-1); is likely to fail on systems that store the full url path in the article text and not the relative url > the $uri->root is then added while it is already present > this results in an faulty image url...
As a quick work around I have changed the code to look like this.
[code]if (version_compare( JVERSION, '1.8', 'ge' ) && isset($images->image_fulltext) and !empty($images->image_fulltext))
{
$og_image = $uri->root() . htmlspecialchars($images->image_fulltext);
$pin_image = $uri->root() . htmlspecialchars($images->image_fulltext);
}
elseif (version_compare( JVERSION, '1.8', 'ge' ) && isset($images->image_intro) and !empty($images->image_intro))
{
$og_image = $uri->root() . htmlspecialchars($images->image_intro);
$pin_image = $uri->root() . htmlspecialchars($images->image_intro);
}
else
{
$og_image = '';
preg_match('/src="([^"]*)"/', $this->item->text, $matches);
if(isset($matches[0])) {
$og_image = substr($matches[0], 5,-1);
$pin_image = $uri->root() . substr($matches[0], 5,-1);
}
}
this additionaly checks on an intro image being present (not only full text image) and it 'fixes' the og_image . Note that I have omitted the $uri->root() on the og_image but that is custom for my sites...
Looking forward to a formal fix