If you’re using Facebook Comments instead of the standard WordPress comments, the comment count functions in WP will return 0 for all posts. I recommend installing EA Share Count, which gathers social share data (including Facebook Comments), then adding the following code to your theme or core functionality plugin. You can then display the comment count with [fb_comments]
.
If EA Share Count is not installed, it falls back to the Genesis comment count shortcode, and if you’re not using Genesis it uses the standard WordPress comment count.
/**
* FB Comments Shortcode
*
*/
function be_facebook_comments_shortcode() {
$output = '';
// Requires EA Share Count, fallback to Genesis shortcode, then to WP comment count
if( function_exists( 'ea_share' ) ) {
$count = ea_share()->core->count( get_the_ID(), 'facebook_comments' );
$text = $count > 0 ? $count . _n( ' Comment', ' Comments', $count ) : 'Leave a Comment';
$output = '<a href="' . get_comments_link( get_the_ID() ) . '" class="entry-comments-link">' . $text . '</a>';
} else {
// Genesis comment shortcode
if( function_exists( 'genesis_post_comments_shortcode' ) ) {
$output = genesis_post_comments_shortcode();
// Standard WP comment count
} else {
$count = get_comments_number();
$text = $count > 0 ? $count . _n( ' Comment', ' Comments', $count ) : 'Leave a Comment';
$output = '<a href="' . get_comments_link( get_the_ID() ) . '" class="entry-comments-link">' . $text . '</a>';
}
}
return $output;
}
add_shortcode( 'fb_comments', 'be_facebook_comments_shortcode' );