Skip to content

Instantly share code, notes, and snippets.

@MaxLynam
Created March 5, 2013 03:46
Show Gist options
  • Save MaxLynam/5087848 to your computer and use it in GitHub Desktop.
Save MaxLynam/5087848 to your computer and use it in GitHub Desktop.
add FB Open Graph & Twitter Cards META to Joomla insert into the appropriate com_content files
if (isset($images->image_intro) and !empty($images->image_intro))
{
$timage= htmlspecialchars(JURI::root().$images->image_intro);
}
elseif (isset($images->image_fulltext) and !empty($images->image_fulltext))
{
$timage= htmlspecialchars(JURI::root().$images->image_fulltext);
}
else
{
$timage= 'http://www.example.com/default-image.jpg';
}
$doc =& JFactory::getDocument();
$doc->addCustomTag( '
<meta name="twitter:title" content="'.$this->escape($this->item->title).'">
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@TwitterUsernameOfWebsite">
<meta name="twitter:creator" content="@TwitterUsernameOfAuthor">
<meta name="twitter:url" content="'.JURI::current().'">
<meta name="twitter:description" content="'.strip_tags($this->item->introtext).'">
<meta name="twitter:image" content="'.$timage.'">
<meta property="og:title" content="'.$this->escape($this->item->title).'"/>
<meta property="og:type" content="article"/>
<meta property="og:email" content="info@example.com"/>
<meta property="og:url" content="'.JURI::current().'"/>
<meta property="og:image" content="'.$timage.'"/>
<meta property="og:site_name" content="Your Website Name Here"/>
<meta property="fb:admins" content="johndoe.3"/>
<meta property="og:description" content="'.strip_tags($this->item->introtext).'"/>
');
@MaxLynam
Copy link
Author

MaxLynam commented Mar 5, 2013

not trialled yet, but looks like a good start ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment