Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created April 15, 2016 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/4810223120445ba55689e3eb0118e4e3 to your computer and use it in GitHub Desktop.
Save billerickson/4810223120445ba55689e3eb0118e4e3 to your computer and use it in GitHub Desktop.
<?php
/**
* 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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment