Skip to content

Instantly share code, notes, and snippets.

@hissy
Created January 19, 2012 00:32
Show Gist options
  • Save hissy/1636750 to your computer and use it in GitHub Desktop.
Save hissy/1636750 to your computer and use it in GitHub Desktop.
Open Graph Tags Setting for concrete5 site
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); ?>
<!-- Open Graph Tags Start -->
<?php
$page = Page::getCurrentPage();
$pageTitle = $page->getCollectionName();
$pageMetaTitle = $page->getCollectionAttributeValue('meta_title');
if ( $pageMetaTitle ) $pageTitle = $pageMetaTitle;
$pageOgTitle = $page->getCollectionAttributeValue('og_title');
if ( $pageOgTitle ) $pageTitle = $pageOgTitle;
$pageOgType = $page->getCollectionAttributeValue('og_type');
if ( !$pageOgType ) $pageOgType = 'article';
?>
<meta property="og:title" content="<?php echo htmlspecialchars($pageTitle, ENT_COMPAT, APP_CHARSET); ?>" />
<meta property="og:type" content="<?php echo $pageOgType; ?>" />
<meta property="og:url" content="<?php echo BASE_URL.DIR_REL.$page->getCollectionPath(); ?>" />
<?php if ( $page->getAttribute('og_image') ) : ?>
<meta property="og:image" content="<?php echo BASE_URL.DIR_REL.$page->getAttribute('og_image')->getVersion()->getRelativePath(); ?>" />
<?php elseif ( $page->getAttribute('page_thumbnail') ) : ?>
<meta property="og:image" content="<?php echo BASE_URL.DIR_REL.$page->getAttribute('page_thumbnail')->getVersion()->getRelativePath(); ?>" />
<?php else : ?>
<meta property="og:image" content="YOUR_DEFAULT_IMAGE" />
<?php endif; ?>
<meta property="og:site_name" content="<?php echo SITE; ?>" />
<meta property="fb:admins" content="YOUR_FB_ID" />
<!-- Open Graph Tags End -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment