+321 123 4567
info@test.com
  • Home
  • My Services
    • Web Design
    • Web Development
    • Technical Writing
  • Portfolio
  • My Thoughts
  • Free Tools
    • Photo Editor
    • Avatar Generator
    • Email Migration Tool
    • QR Code Generator
    • RSS to HTML Converter
    • IP Address Geolocation
    • Base64 Image Encoder
    • NATO Translator
    • All Tools
  • Contact
Home
Wordpress
Adding Facebook Comment to Genesis Without a Plugin

Adding Facebook Comment to Genesis Without a Plugin

Wale Adekile
November 4, 2013

I’ve been working on a radio website built on WordPress over the last few weeks and I decided not to use WP default comment box. As a matter of fact, I disabled it and used Facebook comment box instead. I always believed that you don’t really need a plugin for things that can be manually done on WordPress and went ahead to consult the post I initially wrote on how to how Facebook comment form to Blogger.


I had to make some changes to the code in order to work on WordPress. This code can be used in other WP themes too but since I use Genesis Theme Framework, you need to know what to do to make it work on a different theme.

Basically, the steps are about 4:

  1. Creating a Facebook application
  2. Adding XML namespace and Open Graph tags
  3. Adding the SDK script
  4. Adding the comment box code

1. Creating a Facebook application

a. Head on to facebook developer page, you should create a new app by clicking the button at the top right.

b. Enter your application name and namespace,input the captcha code and proceed.

c. On the next page, enter your custom domain name (if you’re using a custom domain) or just blogspot.com (if you’re using blogspot sub domain) in the space provided for App domain.


For App website, enter you blog URL. ( http://www.xyz.com/ or http://xyz.blogspot.com/ ). Be sure it starts with http:// and ends with / as shown in the screenshot below:

d. Scroll down a bit and hit the Save Changes button. Now you’re done with creating your facebook application but there’s one more thing to do. On that same page, you should see your application ID. Copy it and save somewhere, you’re gonna be needing it.

Well, that’s that.

2. Adding XMNL and Open Graph tags


The open graph meta tags won’t just work for Facebook comments alone, they also make your site appear properly when shared on Facebook. This code adds the required XML namespace and Open Graph Meta Tags. Instead of putting it all together, this code on WPBeginner does it perfectly.

a. Go to Appearance > Editor > functions.php

b. Go to the end of the code and paste this:

//Adding the Open Graph in the Language Attributes
function add_opengraph_doctype( $output ) {
return $output . ' xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"';
}
add_filter('language_attributes', 'add_opengraph_doctype');
//Lets add Open Graph Meta Info
function insert_fb_in_head() {
global $post;
if ( !is_singular()) //if it is not a post or a page
return;
echo '<meta property="fb:admins" content="YOUR FACEBOOK USER ID"/>';
echo '<meta property="fb:app_id" content="YOUR APP ID" />';
echo '<meta property="og:title" content="' . get_the_title() . '"/>';
echo '<meta property="og:type" content="article"/>';
echo '<meta property="og:url" content="' . get_permalink() . '"/>';
echo '<meta property="og:site_name" content="YOUR SITE NAME"/>';
if(!has_post_thumbnail( $post->ID )) { //the post does not have featured image, use a default image
$default_image="http://your-site.com/image.jpg"; //replace this with a default image on your server or an image in your media library
echo '<meta property="og:image" content="' . $default_image . '"/>';
}
else{
$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
echo '<meta property="og:image" content="' . esc_attr( $thumbnail_src[0] ) . '"/>';
}
echo "
";
}
add_action( 'wp_head', 'insert_fb_in_head', 5 );

c. Be sure to change these:

YOUR FACEBOOK USER ID – Replace this with your Facebook user ID. More details here.

YOUR APP ID – Replace this with your app ID

YOUR SITE NAME – Put your site name here

http://your-site.com/image.jpg – Replace with a default image, perhaps your logo

3. Adding Facebook SDK script

a. You have to do this through Genesis hooks and to make things a lot easier, install Genesis Simple Hooks.

b. Go to Simple Hooks, locate genesis_before Hook and paste the code above right there.

<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR APP ID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>

c. Save your change.

4. Adding the comment box code

– Here is the last part of the whole thing. Go to Simple Hooks and locate genesis_after_post_content Hook.

– Copy this code and paste it in the box:

<?php if ( is_single() || is_page()) {?>
<style>
.doncaprio-share-buttons
{
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
border:1px solid #BBBBBB;
background-color:#F2F2F2;
-webkit-box-shadow: #B3B3B3 5px 5px 5px;
-moz-box-shadow: #B3B3B3 5px 5px 5px;
box-shadow: #B3B3B3 5px 5px 5px;
padding: 5px;
margin: 10px;
}
</style>
<p align='center'>
<div class='doncaprio-share-buttons' style='background: #f2f2f2;'>
<div><fb:comments href='<?php the_permalink(); ?>' num_posts='10' width='450'></fb:comments></div>
</div>
</p>
<?php }?>

Save the change.

If done right, the comment box should appear below post content and static pages but you can change this by manipulating the conditional statement if you want the comment box to appear on posts only.


Previous Post
When Should You Consider Upgrading Your Business Email System?
Next Post
Fix: Blog Post Sharing on Facebook with No Title & Thumbnail
Wale Adekile
Husband to the world's most beautiful woman and father to two awesome kids. A nerd, obviously; also, a technical business analyst, a web designer who preaches the gospel of WordPress, and a writer. You can check out my published books on Amazon.
how to insert google adsense into wordpress mobile version
Wordpress

Inserting Google Adsense Ads in WordPress Mobile Version

14 years ago
breadcrumb navigation for blogspot
BloggerWordpress

Displaying Breadcrumb in Google Search Result for Blogger & WordPress

13 years ago

Recent Articles

wahl rapic clip hair clipper
Wahl Rapid Clip Hair Clipper Review: DIY Made Easy
BenQ LaptopBar Review: Luxury or Necessity?
yunmai easepro unboxed
Yunmai EasePro Massage Gun Review
g20
Teendow G20 Robot Vacuum and Mop Review
bathroom
Dear Men, Spraying All Over the Toilet Seat is Disgusting and Irresponsible
winx mediatrans
How to Transfer Photos from iPhone to Computer Without iTunes
google workspace
How to Migrate Emails From Google Workspace/G Suite to cPanel
synology diskstation ds920+
Synology DiskStation DS920+ Review
playstation 4
Why I haven’t Upgraded to the PlayStation 5 Yet
pain
Started Watching Anime as an Adult? You’re Not Alone

All contents on this blog are copyright protected and cannot be reproduced on other websites without permission.

Copyright © 2022 – NerdieDad | Home | Contact | About | Privacy Policy