Facebook OpenGraph tags for a Wordpress site


/ Published in: PHP
Save to your folder(s)

To be used in the header.php


Copy this code and paste it in your HTML
  1. <meta property="fb:admins" content="[Your FB app ID]" />
  2.  
  3. <!-- if page is content page -->
  4. <?php if (is_single()) { ?>
  5. <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
  6. <meta property="og:url" content="<?php the_permalink() ?>"/>
  7. <meta property="og:title" content="<?php single_post_title(''); ?>" />
  8. <meta property="og:description" content="<?php echo strip_tags(get_the_excerpt($post->ID)); ?>" />
  9. <meta property="og:type" content="article" />
  10. <?php endwhile; else: endif; ?>
  11. <!-- if page is others -->
  12. <?php } else { ?>
  13. <meta property="og:site_name" content="<?php bloginfo('name'); ?>" />
  14. <meta property="og:description" content="<?php bloginfo('description'); ?>" />
  15. <meta property="og:type" content="website" />
  16. <?php } ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.