Tweak You WordPress Post for better Facebook Share


Sponsored Links




Facebook 3D LogoThis code created by Chad Von, a WordPress and Content Management Systems and eCommerce for Business Websites. I live up north in Coeur d’Alene, Idaho. This code is to make your WordPress Post have better view when shared on Facebook. This code need to be added on your header.php to make it work.

This code is added new metadata for Facebook. This metadata only available on single and page. Let’s get started. Open your header.php and re write this code.

<?php
	$thumb = get_post_meta($post->ID,'_thumbnail_id',false);
	$thumb = wp_get_attachment_image_src($thumb[0], false);
	$thumb = $thumb[0];
	$default_img = get_bloginfo('stylesheet_directory').'/images/default_icon.jpg';
	?>

<?php if(is_single() || is_page()) { ?>
	<meta property="og:type" content="article" />
	<meta property="og:title" content="<?php single_post_title(''); ?>" />
	<meta property="og:description" content="<?php
	$out_excerpt = str_replace(array("rn", "r", "n"), "", get_the_excerpt());
	echo apply_filters('the_excerpt_rss', $out_excerpt);
	?>" />
	<meta property="og:url" content="<?php the_permalink(); ?>"/>
	<meta property="og:image" content="<?php if ( $thumb[0] == null ) { echo $default_img; } else { echo $thumb; } ?>" />
<?php  } else { ?>
	<meta property="og:type" content="article" />
   <meta property="og:title" content="<?php bloginfo('name'); ?>" />
	<meta property="og:url" content="<?php bloginfo('url'); ?>"/>
	<meta property="og:description" content="<?php bloginfo('description'); ?>" />
    <meta property="og:image" content="<?php  if ( $thumb[0] == null ) { echo $default_img; } else { echo $thumb; } ?>" />
<?php  }  ?>

Please notes, you need put this code inside <head> and before </head> to make it works

You check more details on Chad Von blogs.

Subscribe to Full RSS Feed

RSS FeedIf you thing this article useful, please consider subscribing to our RSS Feed or e-mail updates and stay updated with us. You can also follow @WPTricksNet on twitter for latest updates.

About WP Tricks

We are WordPress Family, we collected and writed useful tips and tricks for you WordPress. We share it for you...

Related Tips and Trick from Local Data and on The Net

Like Button - Facebook Developers

The Like button lets a user share your content with friends on Facebook. When the user clicks the Like button on your site, a story appears in the user's friends Read More

My Most Successful Facebook Page Tweak to Date

to write my reveal page in WordPress. I used the "Add new post Have you seen any creative Facebook landing pages that you in My Most Successful Facebook Page Tweak to Read More

How to Avoid No Thumbnail Issue While Sharing Post on Facebook

Have you ever tried clicking on a Facebook Share link from a blog post just to end up dynamic platform like WordPress, we need to tweak You are better off asking this Read More

Some Facebook Fan Page Tweaks and Tips for Lodging | Chefforfeng's

can be as long as you want. Wall post length unlimited tabs (wish to facebook, have a better You are commenting using your WordPress.com account. Read More

With Google+ (And A Tweak For Analytics), The Social Sharing War

fact that it was far too slow to share content on Facebook. Notably, Facebook has gotten much better at facilitating sharing service that allows users to post Read More


5 Responses to Tweak You WordPress Post for better Facebook Share

  1. That’s awesome! I never thought to use an if statement with og meta before, that’s really interesting thanks for a top tip :-)

  2. Pingback: Dacă vă dispare editorul vizual la upgrade-ul la Wordpress 3.1

  3. Pingback: Tweak You WordPress Post for better Facebook Share | Jhez3R

  4. Alex Mielus says:

    The description part it’s a tricky one ;) You may want to delete or at least comment it out. Other that that … awesomeness.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>