How to add META Tags to FLEXIContent Items

More
6 years 11 months ago - 6 years 11 months ago #67357 by iamrobert
I was thinking about how to add images for meta tags:
moz.com/blog/meta-data-templates-123

In item.php
Code:
//GET PAGE URL $siteURL='http'.(empty($_SERVER['HTTPS'])?'':'s').'://'.$_SERVER['SERVER_NAME']; //CALL YOUR IMAGE FIELD $url = FlexicontentFields::getFieldDisplay($item, 'fieldname', null, 'display_large_src', 'item'); $document = JFactory::getDocument(); if(!empty($url)) { $document->setMetaData( 'twitter:image', ''.$siteURL.$url.'' ); $document->setMetaData( 'og:image', ''.$siteURL.$url.'' ); }

In your template's index.php or item.php you can add - depends if its global or not:
Code:
$document = JFactory::getDocument(); $document->setMetaData( 'og:type', 'article' ); $document->setMetaData( 'og:site_name', '' .htmlspecialchars($app->getCfg('sitename')).'' ); $document->setMetaData( 'og:url', ''.JUri::getInstance().'' );

Call og:description & twitter:description in item.php:
Code:
if(!empty ($item->metadesc)) { //CALL METADESCRIPTION EXISTS $document->setMetaData('twitter:description',''.$item->metadesc.''); $document->setMetaData('og:description',''.$item->metadesc.''); } elseif (!empty ($item->fields['text']->display)) { //CALL IF INTRO EXISTS $document->setMetaData('twitter:description',''.flexicontent_html::striptagsandcut($item->introtext,'200').''); $document->setMetaData('og:description',''.flexicontent_html::striptagsandcut($item->introtext,'200').''); }


Call Date & Times in item.php:
Code:
//TIMES + DATES $published_date = new DateTime($item->publish_up); $modified_date = new DateTime($item->modified); $expiry_date = new DateTime($item->publish_down); if(!empty ($published_date)) { $document->setMetaData('article:published_time',''.$published_date->format(DateTime::ATOM).''); } if(!empty ($modified_date)) { $document->setMetaData('article:modified_time',''.$modified_date->format(DateTime::ATOM).''); } if ($expiry_date != '0000-00-00 00:00:00') { $document->setMetaData('article:expiration_time',''.$expiry_date->format(DateTime::ATOM).''); } //ADD CATEGORY TITLE global $globalcats; $cat_title = flexicontent_html::striptagsandcut($globalcats[$item->catid]->title); if(!empty ($cat_title)) { $document->setMetaData('article:section',''.$cat_title.''); }
Last edit: 6 years 11 months ago by iamrobert.

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.259 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline