Skip to content

Instantly share code, notes, and snippets.

@daviddarnes
Last active January 19, 2017 23:16
Show Gist options
  • Save daviddarnes/5735237 to your computer and use it in GitHub Desktop.
Save daviddarnes/5735237 to your computer and use it in GitHub Desktop.
Open Graph meta information for Facebook and Google+
<!-- Open graph meta -->
<meta property="og:type" content="website">
<meta property="og:site_name" content="<?php echo site_name(); ?>">
<?php if(is_homepage() == true) : ?>
<meta property="og:url" content="http://websiteaddress.com">
<meta property="og:title" content="<?php echo site_name(); ?>">
<meta property="og:description" content="<?php echo site_description(); ?>">
<?php else: ?>
<meta property="og:url" content="<?php echo "http://websiteaddress.com/" . current_url(); ?>">
<meta property="og:title" content="<?php echo page_title('Page can’t be found'); ?> - <?php echo site_name(); ?>">
<meta property="og:description" content="<?php if(strlen(article_description())) : echo article_description(); else: echo site_description(); endif; ?>">
<?php endif; ?>
<!-- If you have any image custom fields -->
<?php $thumbnail = article_custom_field('thumbnail');
if ( !empty($thumbnail) ) : ?>
<meta property="og:image" content="<?php echo "http://websiteaddress.com" . $thumbnail; ?>">
<?php else: ?>
<meta property="og:image" content="<?php echo "http://websiteaddress.com" . theme_url('img/logo.png'); ?>">
<?php endif; ?>
@dannyrb
Copy link

dannyrb commented Mar 10, 2015

@cinoyter -- I had a similar issue with is_homepage(); Thanks for taking the time to post a fix. I also found this write-up that shows how to add support Twitter Cards and Search Engine MicroData:

http://lug.io/blog/posts/adding-semantic-markup-to-anchor-cms

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