How to set default image for Facebook sharing in WordPress blog posts ?

A picture equals to many words. Facebook can be the biggest traffic source for your website, web 2.0 is social web. It may happen that your article is very catchy, get shared many times on Facebook but many of them don’t click the link. Attaching certain picture may increase click rate of Facebook news feed.

Increase of click rate means increased visitors, increased social sharing. To select certain image for a post you need to add some meta tags in header. Its obvious that we need different meta tags for each post. Static meta tags won’t do.

We will add a custom field and then fetch it in header file.

Add a custom field named “fbimage”. On post edit page under “Custom Fields” click enter new. Type “fbimage” and under value type image name you want to select for that post. ( Upload the image to wp-content/uploads)

( Note that you need to add new custom field only once, next time you just need to enter only value selecting field name from dropdown )

Update the post.

Now edit your theme from Appearance –> Editor. Select header.php.

Anywhere between <head> to </head> add below code.

<?php if(is_single()){ $values = get_post_custom_values(‘fbimage’,$post->ID); if($values[0]!=”){?>
<meta property=”og:image” content=”http://www.example.com/wp-content/uploads/<?php $values = get_post_custom_values(‘fbimage’,$post->ID); echo $values[0]; ?>”/>
<link rel=”image_src” href=”http://www.example.com/wp-content/uploads/<?php $values = get_post_custom_values(‘fbimage’,$post->ID); echo $values[0]; ?>” / >
<?php
}}
?>

Update the file and you’re done.

From next time you write a post, add value to “fbimage” custom field and enjoy increased click rate.

 

Advertisements

Festive Offer

Festive Offer

Festive Offer:: make Your Website $100/once
1. WordPress CMS World’s Most user frendly cms system
2. Domain Hosting for 1 year after 1 year you can renew the hosting.
3. Homepage + Unlimited Innerpages custom layout designing as per your requirement.
4. WordPress CMS systems manage your site with most popular open source CMS.
5. 10 Email id from your domain (GMail Integrate)
6. No Monthly cost

Email: krushna.c@gmail.com

%d bloggers like this: