Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active October 12, 2018 13:28
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/4250ac6942e7da6365e29950a52b224f to your computer and use it in GitHub Desktop.
Save billerickson/4250ac6942e7da6365e29950a52b224f to your computer and use it in GitHub Desktop.
<?php
/**
* Include Shared Counts in Display Posts Shortcode
*
* @author Bill Erickson
* @see https://www.billerickson.net/code/shared-counts-display-posts-shortcode/
*/
function be_shared_counts_dps( $output, $original_atts, $image, $title, $date, $excerpt, $inner_wrapper, $content, $class, $author, $category_display_text ) {
// Check for include_shared_counts="true"
if( ! ( isset( $original_atts['include_shared_counts'] ) && filter_var( $original_atts['include_shared_counts'], FILTER_VALIDATE_BOOLEAN ) )
return $output;
// Make sure Shared Counts is active
if( ! function_exists( 'shared_counts' ) )
return $output;
$style = !empty( $original_atts['shared_counts_style'] ) ? esc_attr( $original_atts['shared_counts_style'] ) : false;
$share = shared_counts()->front->display( $location = 'dps', $echo = false, $style );
$output = '<' . $inner_wrapper . ' class="' . implode( ' ', $class ) . '">' . $share . $image . $title . $date . $author . $category_display_text . $excerpt . $content . '</' . $inner_wrapper . '>';
return $output;
}
add_action( 'display_posts_shortcode_output', 'be_shared_counts_dps', 10, 11 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment