Codeable info

How To Add A Facebook “Like” Button Under Each Post

Posted on by in WordPress Tutorials

How To Add A Facebook "Like" Button Under Each PostEveryone uses Facebook, and as far as blogs and WordPress sites are concerned Facebook could provide great exposure and free advertising. The best way to garner a bigger following is to allow your readers and site users to tell the world they like your content.

The best way to implement such a feature is to add a Facebook “Like” button underneath each new and archived post.

The required code is quite simple and involves editing the current/active themes “function.php” source file, so make sure to back up your WordPress database in case something goes wrong.

Open your active themes “functions.php” source file, as I mentioned above, and scroll all the way down to the last line which should resemble the following:

?>

Input a space directly above that final line and include the following code:

function wpcode_like($wpc_fb_like = '') {
global $post;
 
if(is_single() || is_home() || is_page() || is_archive()) { 
 
$wpc_fb_like .= 'ID)) .
                    '&layout=standard&show_faces=true&width=408&action=like&font=verdana&colorscheme=light" scrolling="no"               frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:408px; height:80px">';
 
    }
    return $wpc_fb_like;
}
add_filter('the_content', 'wpcode_like');

If you would like the “Like” button only to display on the most recent post and not show up in the archive posts simply swap out the following two lines.

Swap out this:

if(is_single() || is_home() || is_page() || is_archive()) {

With this:

if(is_single() || is_home() || is_page()) {

Thats it! Now save the file and your blog should reflect the changes (refresh your browser window if you had your blog open). For good practice sign in with your personal Facebook account and start clicking those “Like” buttons!

For reference, here’s an example of how this feature looks in the field.

)
Codeable info

Comments (1)

Comment by Jenni says:

hi,

Please help me.
i want to add facebook like page button on each post. when i updated new post on facebook page. help me .

Codeable info