Last active
January 19, 2017 23:16
-
-
Save daviddarnes/5735237 to your computer and use it in GitHub Desktop.
Open Graph meta information for Facebook and Google+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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; ?> |
It seems that is_homepage() == true is always evaluating to true, so it always writes out the meta tags for the homepage, not the posts. As a workaround, I replaced this expression with:
if(current_url() == "/" || current_url() == "posts") :
and it seems to work correctly.
@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
Hey David, sorry for the silence. Your code does not pull the article description, even though i set both arguments to "article_description". It also does not grab my sidebar image, which i use as a custom field (theme is Bushwick by molovo). Here's my code, maybe i'm just too dumb?