How to Use Manual Social Button Placement with the New Facebook Plugin for WordPress

The new Facebook plugin for WordPress is really nice — well written and uses only the best practices in WordPress plugin development. Here a few tips to help you customize the functionality of the plugin.

Customizing the Social Sharing Button Location

All of the sharing buttons are added automatically to your post content (both before and after it), which is a kind of behavior that you might want to overwrite from within the theme. The four filters it uses are the following (in social-plugins/fb-social-plugins.php):

add_filter( 'the_content', 'fb_recommendations_bar_automatic', 30 );
add_filter( 'the_content', 'fb_like_button_automatic', 30 );
add_filter( 'the_content', 'fb_send_button_automatic', 30 );
add_filter( 'the_content', 'fb_subscribe_button_automatic', 30 );

In order to remove the automatic placement of those buttons, simply remove the filters by running remove_filter (in functions.php, for example):

remove_filter( 'the_content', 'fb_recommendations_bar_automatic' );
remove_filter( 'the_content', 'fb_like_button_automatic' );
remove_filter( 'the_content', 'fb_send_button_automatic' );
remove_filter( 'the_content', 'fb_subscribe_button_automatic' );

and then define a set of custom actions that you’ll call in the exact places where you want the buttons to appear in your theme files. For example, here is an example of a custom action for the Like button that you’ll define in the functions.php and then use the do_action call in the places you want to echo the button:

add_action( 'my_fb_like_button', 'get_my_fb_like_button', 10 );

function get_my_fb_like_button() {
	$options = get_option( 'fb_options' );

	echo fb_get_send_button( $options['send'] );
}

And then in index.php, single.php and page.php, you call:

<div class="social-buttons">
	<?php do_action( 'my_fb_like_button' ); ?>
	Your other social buttons...
</div>

This way it will not brake your site if you deactivate or remove the plugin.

No Syncing of Facebook Comments with WordPress

This is my bigest gripe with the plugin — you still don’t get a complete and proper integration of Facebook comments with WordPress built-in comment system. What they call “Comments with SEO support” is actually retrieving comments from Facebook and caching them in the transients table, and displaying them on posts inside <noscript> with follow links to the Facebook profiles of the comment authors. I really wish they either improve this or somebody creates a plugin that adds this feature.

Use Contact Form 7 to collect business leads and enquiries? I created Storage for Contact Form 7 plugin which stores them safely in WordPress database.

Get it now for only $19 →

2 Comments

  1. chetan says:

    Hi,

    I used the code is stop showing the recommendation bar on pages but it wont work. I tried:

    add_action( 'my_fb_like_button', 'get_my_fb_like_button', 10 );

    [code snippets removed]

  2. Kaspars says:

    chetan, you should use remove_action with the correct action call instead. Try adding all of the remove_action calls to see if it works.

Leave a Reply