Support Online : Mon - Fri / 10am - 6pm (GMT +6)

Your Time: Our Time:

Open Graph assist

Featured Lock Resolved Issue
Hi! I have a website and I'm using the resource provided by Politist, which is the blog.
To show the image we use "Helix Blog Options", where you can set a Featured Image.
So when I do post an article setting and image in it I want to automatically create the tag with og:image from facebook with this image aswell.

To make myself more clear.
1 - I created an article;
2 - Set an image into Helix Blog Options > Featured Image
3 - I want to automatically create < meta property="og:type" content=".....jpg" > from the image set up into Helix Blog Options > Featured image.

The website I'm using is http://www.cristianoalmeidabp.com.br and you can see that I already have all the meta tags, but can't figure out how to get the image automatically.
See here: http://www.cristianoalmeidabp.com.br/atuacao/ultimas-noticias/97-dando-voz-aos-distritos-fala-dorandia

I Hope you guys can help me out.
Thanks in advance.

11 Answers

Paul Frankowski - Staff

More than a month ago #Permalink
Hi,
I have to check if in current version of template I can do something, if not, I will give you tip or ask to wait for template update.

Paul Frankowski - Staff

More than a month ago #Permalink
Ok, last questions ::
1) Are you using any sort of plugin for Open Graph ?
2) Have you edited that file: templates\shaper_politcs\html\com_content\article\default.php
-----

Open Graph tags can added to that template, because right now they are not included.
In means that you can disable Open Graph plugin if you have any.
And paste following code:


//get image
$article_attribs = json_decode($this->item->attribs);
$article_images = json_decode($this->item->images);
$article_image = '';
if(isset($article_attribs->spfeatured_image) && $article_attribs->spfeatured_image != '') {
$article_image = $article_attribs->spfeatured_image;
} elseif(isset($article_images->image_fulltext) && !empty($article_images->image_fulltext)) {
$article_image = $article_images->image_fulltext;
}

//opengraph
$document = JFactory::getDocument();
$document->setTitle($this->item->title);
$document->addCustomTag('<meta property="og:url" content="'.JURI::current().'" />');
$document->addCustomTag('<meta property="og:type" content="article" />');
$document->setDescription( JHtml::_('string.truncate', $this->item->introtext, 155, false, false ) );
$document->addCustomTag('<meta property="og:title" content="'. $this->item->title .'" />');
$document->addCustomTag('<meta property="og:description" content="'. JHtml::_('string.truncate', $this->item->introtext, 155, false, false ) .'" />');
if ($article_image) {
$document->addCustomTag('<meta property="og:image" content="'. JURI::root().$article_image.'" />');
$document->addCustomTag('<meta property="og:image:width" content="600" />');
$document->addCustomTag('<meta property="og:image:height" content="315" />');
}

$post_format = $params->get('post_format', 'standard');
$has_post_format = $tpl_params->get('show_post_format');
if($this->print) $has_post_format = false;





here: templates\shaper_politcs\html\com_content\article\default.php

before closing ?>
<article


---
If you afraid to do that, just download a zip file , unzip and replace

Attachments (1)

  • default.zip 2.5 KB

Fator 3 Informática

More than a month ago #Permalink
Hi,
I have to check if in current version of template I can do something, if not, I will give you tip or ask to wait for template update.

Hi! Sending you the attachment with the versions.
I'm afraid to update it, since the site is already live, can't take any risk of breaking things, and I don't have subscription to Page Builder to download the last version and update it.

Attachments (1)

  • politist-version.PNG
    politist-version.PNG 25.4 KB

Fator 3 Informática

More than a month ago #Permalink
Ok, last questions ::
1) Are you using any sort of plugin for Open Graph ?
2) Have you edited that file: templates\shaper_politcs\html\com_content\article\default.php
-----

Open Graph tags can added to that template, because right now they are not included.
In means that you can disable Open Graph plugin if you have any.
And paste following code:


//get image
$article_attribs = json_decode($this->item->attribs);
$article_images = json_decode($this->item->images);
$article_image = '';
if(isset($article_attribs->spfeatured_image) && $article_attribs->spfeatured_image != '') {
$article_image = $article_attribs->spfeatured_image;
} elseif(isset($article_images->image_fulltext) && !empty($article_images->image_fulltext)) {
$article_image = $article_images->image_fulltext;
}

//opengraph
$document = JFactory::getDocument();
$document->setTitle($this->item->title);
$document->addCustomTag('<meta property="og:url" content="'.JURI::current().'" />');
$document->addCustomTag('<meta property="og:type" content="article" />');
$document->setDescription( JHtml::_('string.truncate', $this->item->introtext, 155, false, false ) );
$document->addCustomTag('<meta property="og:title" content="'. $this->item->title .'" />');
$document->addCustomTag('<meta property="og:description" content="'. JHtml::_('string.truncate', $this->item->introtext, 155, false, false ) .'" />');
if ($article_image) {
$document->addCustomTag('<meta property="og:image" content="'. JURI::root().$article_image.'" />');
$document->addCustomTag('<meta property="og:image:width" content="600" />');
$document->addCustomTag('<meta property="og:image:height" content="315" />');
}

$post_format = $params->get('post_format', 'standard');
$has_post_format = $tpl_params->get('show_post_format');
if($this->print) $has_post_format = false;





here: templates\shaper_politcs\html\com_content\article\default.php

before closing ?>
<article


---
If you afraid to do that, just download a zip file , unzip and replace


Hi!
1) Yes. I'm using Phoca Open Graph. Latest version.
2) No. I didn't change any file.

Fator 3 Informática

More than a month ago #Permalink
What do you recommend me to do?
1) Update it all, disable open graph plugin and then install the code?
2) Disable open graph plugin and install the code without any update?

I'm kind lost in here hehehe

Paul Frankowski - Staff

More than a month ago #Permalink
Disable open graph plugin
then use my file (default.php) to replace old file.
That's all.
---
or if you have skills , you can customize Phoca Open Graph tool. hehehe

Fator 3 Informática

More than a month ago #Permalink
Disable open graph plugin
then use my file (default.php) to replace old file.
That's all.
---
or if you have skills , you can customize Phoca Open Graph tool. hehehe


I also can do that. But I would like to know which code will capture the image from Helix Blog.
If you can tell me that =P

Paul Frankowski - Staff

More than a month ago #Permalink
first part of my previous code


//get image
$article_attribs = json_decode($this->item->attribs);
$article_images = json_decode($this->item->images);
$article_image = '';
if(isset($article_attribs->spfeatured_image) && $article_attribs->spfeatured_image != '') {
$article_image = $article_attribs->spfeatured_image;
} elseif(isset($article_images->image_fulltext) && !empty($article_images->image_fulltext)) {
$article_image = $article_images->image_fulltext;
}



I guess.

Fator 3 Informática

More than a month ago #Permalink
Disable open graph plugin
then use my file (default.php) to replace old file.
That's all.
---
or if you have skills , you can customize Phoca Open Graph tool. hehehe


Got it to work with Phoca Open Graph.
Include some code that you past here.

First I add

$article_attribs = json_decode($row->attribs);

Had to change the $this->item for $row->

Then below I add this if

if(isset($article_attribs->spfeatured_image) && $article_attribs->spfeatured_image != '') {
$pictures = $article_attribs->spfeatured_image;
$document = JFactory::getDocument();
$document->addCustomTag('<meta property="og:image" content="'. JURI::root().$pictures.'" />');
$imgSet = 1;
}


Thanks for the help!

markmark

More than a month ago #Permalink
Hy!
And this version perfect for Helix Ultimate... :

i use in default.php top...

after:

defined ('_JEXEC') or die();

use Joomla\CMS\HTML\HTMLHelper;
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers');


addedand modified this:


//get image
$article_attribs = json_decode($this->item->attribs);
$article_images = json_decode($this->item->images);
$article_image = '';
if(isset($article_attribs->helix_ultimate_image) && $article_attribs->helix_ultimate_image != '') {
$article_image = $article_attribs->helix_ultimate_image;
} elseif(isset($article_images->image_fulltext) && !empty($article_images->image_fulltext)) {
$article_image = $article_images->image_fulltext;
}

//opengraph
$document = JFactory::getDocument();
$document->setTitle($this->item->title);
$document->addCustomTag('<meta property="og:url" content="'.JURI::current().'" />');
$document->addCustomTag('<meta property="og:type" content="article" />');
$document->setDescription( JHtml::_('string.truncate', $this->item->introtext, 155, false, false ) );
$document->addCustomTag('<meta property="og:title" content="'. $this->item->title .'" />');
$document->addCustomTag('<meta property="og:description" content="'. JHtml::_('string.truncate', $this->item->introtext, 155, false, false ) .'" />');
if ($article_image) {
$document->addCustomTag('<meta property="og:image" content="'. JURI::root().$article_image.'" />');
$document->addCustomTag('<meta property="og:image:width" content="600" />');
$document->addCustomTag('<meta property="og:image:height" content="315" />');
}


There are no replies made for this post yet.
Be one of the first to reply to this post!

Leaderboard (30 days)

Paul Frankowski

Paul Frankowski

Total Accepted Answers: 107
Sifat

Sifat

Total Accepted Answers: 62
Toufiq

Toufiq

Total Accepted Answers: 47
Mehtaz Afsana Borsha

Mehtaz Afsana Borsha

Total Accepted Answers: 20
Rashida Rahman

Rashida Rahman

Total Accepted Answers: 12

118

Templates

303288

Community Users

Newsletter

Don’t miss any updates of our new templates and extensions and all the astonishing offers we bring for you.
We never spam

Joomla! ® name is used under a limited license from Open Source Matters in the United States and other countries. JoomShaper.com is not affiliated with or endorsed by Open Source Matters or the Joomla! Project.

Connect Us