-
-
Save daviddarnes/5735237 to your computer and use it in GitHub Desktop.
<!-- 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; ?> |
@pReya What kind of error are you getting?
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?
<!-- 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://netchild.de">
<meta property="og:title" content="<?php echo site_name(); ?>">
<meta property="og:description" content="<?php if(strlen(article_description())) : echo article_description(); else: echo site_description(); endif; ?>">
<?php else: ?>
<meta property="og:url" content="<?php echo "http://netchild.de/" . 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('sidebar_image');
if ( !empty($sidebar_image) ) : ?>
<meta property="og:image" content="http://netchild.de/content/sidebar-bg2.jpg">
<?php else: ?>
<meta property="og:image" content="http://netchild.de/content/sidebar-bg2.jpg">
<?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
Hey David,
i really appreciate this snippet, even though it doesn't seem to work perfectly. Somehow i always end up with the general site description and title, even though i am using an article url. Just like "chrisod" in the Anchor Forums: http://forums.anchorcms.com/discussion/linking-to-anchor-posts-from-facebook-google
Is there any chance you can help me, integrating the Open Graph Meta data correctly into my Anchor Theme (http://bushwick.molovo.co.uk/). I'd really appreciate it!
Best,
Moritz