How to add META Tags to FLEXIContent Items

1 year 5 months ago - 1 year 5 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
//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:
$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:
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:
//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.'');
}

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

Moderators: vistamediajoomlacornerggppdk
© 2018 Flexicontent. All Rights Reserved.