813-319-4253 | Client Area

Make Joomla articles deliver the correct metadata to social networks

You don't need any special extension to get a Joomla article to supply image and other valid meta data to social networks. While the article component does not natively include a method to feed networks, the template override system makes it possible for a user to add the function to their template.

  1. Use the template override function to create an article override template
  2. Edit the file, now in your default template at templates/yourtmpl/html/com_content/article/default.php
  3. Add the following code lines at the top, right after the line JHtml::_('behavior.caption);

//-----------------------------[ Add Article Social Media Meta Tags ]----------------------//
$document = JFactory::getDocument();
$item = $this->item;

$metadesc = $document->getMetaData('description');
if( !empty($item->metadesc) ) {
   // get description from article metadesc field if set
   $metadesc = $item->metadesc;
   // get first 150 characters from text area of article
   $metadesc = strip_tags(substr($item->introtext, 0, 150));

$document->setMetaData('og:site_name', JFactory::getApplication()->get('sitename'), 'property');

// this line is optional. be sure to replace the sample appID to your own
$document->setMetaData('fb:app_id', 'JH58R6745RTh90', 'property');
// this line is optional
$document->setMetaData('article:publisher', 'https://www.facebook.com/mygreatfbpage', 'property');

$document->setMetaData('og:url', substr(Juri::base(),0,-1).JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid, $item->language)), 'property');
$document->setMetaData('og:title', $item->title, 'property');
$document->setMetaData('twitter:title', $item->title);
$document->setMetaData('og:description', $metadesc, 'property');
$document->setMetaData('twitter:description', $metadesc);
$document->setMetaData('twitter:card', 'summary');
if( !empty($images->image_intro) ) {
   $document->setMetaData('og:image', Juri::base().$images->image_intro, 'property');
   $document->setMetaData('twitter:image', Juri::base().$images->image_intro);
}elseif( !empty($images->image_fulltext) ) {
   $document->setMetaData('og:image', Juri::base().$images->image_fulltext, 'property');
   $document->setMetaData('twitter:image', Juri::base().$images->image_fulltext);
$document->setMetaData('og:image:width', '600', 'property');
$document->setMetaData('og:image:height', '315', 'property');
// if you want to strip the default generator statement

From then on all your shared articles will provide the correct info. You can test the shared URLs at FaceBook and Twitter to see what is scraped.
Twitter validator: https://cards-dev.twitter.com/validator
FaceBook debugger: https://developers.facebook.com/tools/debug/og/object/

Category: Website Tips |

Assisted Annual Hosting $83.40

  • CPanel Hosting ready immediately
  • WordPress or Joomla system installed and configured to suit your needs.


  • Shopping Cart, Blog, Magazine, News, Video, Internet Radio, Church, Medical, Real Estate, Business Directory, Classifieds, Auto Trading etc
  • $20 Facebook marketing credit to immediately promote the website to over 10,000 viewers

Get Hosting Now

Service Expertise

WebsiteDons.com specializes in Joomla©™, WordPress©™ and Drupal©™ Content Management Systems which have all been award winning and most popular website operating systems. WebsiteDons.com is a one stop website services center for all your website solutions including unlimited web hosting, website design and development, search engine optimization and website search engine marketing. WebsiteDons.com have produced and supported over 4300 websites very efficiently and helped many clients achieve success online.

The single web hosting plan makes it simple for any small business to make the most of an online presence without muddling through numerous technical options which just leads to confusion.

WebsiteDons.com 813-319-4253 Owned and operated by Emuzement Net Inc.

Copyright © 2019 WebsiteDons.com. All Rights Reserved.