jaredatch / Shared-Counts

WordPress plugin that leverages SharedCount.com API to quickly retrieve, cache, and display various social sharing counts.
GNU General Public License v2.0
47 stars 16 forks source link

Don't display "Included Total" button if 0 shares and "hide empty counts" is true #44

Closed billerickson closed 5 years ago

billerickson commented 6 years ago

We currently display the "Included Total" button whether or not there are any shares. If "Hide Empty Counts" is checked, the 0 is removed but the button itself stays, so it just says "Shares".

screenshot

This makes sense in the context of the other buttons (the FB share button should appear regardless of the share count), but not so with this button.

I think we should remove the "Included Total" button entirely if "hide empty counts" is true and the share count is zero.


Until this is patched and publicly released, you can implement this on your own site by adding the following to your theme's functions.php file or a core functionality plugin.

/**
 * Shared Counts, don't display total if 0 counts
 *
 */
function be_shared_counts_remove_empty_total( $element, $link ) {
    if( 'included_total' == $link['type'] && empty( $link['count'] ) ) {
        $element['wrap_open'] = $element['icon_label'] = $element['icon_count'] = $element['wrap_close'] = '';
    }
    return $element;
}
add_filter( 'shared_counts_output_elements', 'be_shared_counts_remove_empty_total', 10, 2 );
JiveDig commented 5 years ago

Just chiming in to say I tested develop just now and it fixed this issue for me as well 👍