Elxis CMS Forum

Support => General => Topic started by: peppemania on May 25, 2015, 13:18:51

Title: Open Graph
Post by: peppemania on May 25, 2015, 13:18:51
You can modify component content (controllers article and category) and add any meta data you like.

Example to set META name/content pairs using setMetaTag method:
$eDoc->setMetaTag('description', 'some description');
The above will generate this:
<meta name="description" content="some description" />

...
index template:
$eDoc->addCustom('<meta property="og:site_name" content="Moz" />');
...
but automatic meta for open graph?
<meta property="og:image" content="URL_IMAGE_ATICLE.JPG"/>

I ask because Facebook does not share pictures of articles, but randomly chooses from the full page
Title: Re: Open Graph
Post by: datahell on May 25, 2015, 21:21:49
Use method addCustom

$eDoc->addCustom('<meta property="og:image" content="URL_IMAGE_ATICLE.JPG"/>');
Title: Re: Open Graph
Post by: peppemania on May 25, 2015, 21:44:40
ok datahell, but for each article? no automatic metod?
Title: Re: Open Graph
Post by: datahell on May 26, 2015, 17:12:51
You can do it 3 ways:

1. Develop a special plugin.
2. Write some php code in template that will detect "ELXIS_ARTID" constant. Then query the database to get the image and insert the meta tag you want.
3. Edit component content:
open file components/com_content/controllers/article.php
Go to line 161:
$eDoc->setKeywords($row->keywords['total']);

Add below:
if ($row->image != '') {
    $imgfile = $elxis->secureBase().'/'.$row->image;
    $eDoc->addCustom('<meta property="og:image" content="'.$imgfile.'"/>');
}