Skip to content

Instantly share code, notes, and snippets.

@cgrymala
Created November 14, 2013 17:21
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 cgrymala/7470688 to your computer and use it in GitHub Desktop.
Save cgrymala/7470688 to your computer and use it in GitHub Desktop.
Brief example showing how to remove a filter (in this case, the "Sharing" buttons that JetPack outputs at the end of content) within WordPress.
<?php
function output_featured_image() {
echo '<figure class="featured-image">';
the_post_thumbnail( 'archive-feature', array( 'class' => 'alignnone' ) );
// First, check to see if the Sharing buttons are supposed to display on content or excerpt
// Remove those sharing buttons if they are
$sharecontent = false;
$shareexcerpt = false;
if ( has_filter( 'the_content', 'sharing_display' ) ) {
$sharecontent = true;
remove_filter( 'the_content', 'sharing_display', 19 );
}
if ( has_filter( 'the_excerpt', 'sharing_display' ) ) {
$shareexcerpt = true;
remove_filter( 'the_excerpt', 'sharing_display', 19 );
}
echo '<figcaption>';
// Output the content you want to output here, without the sharing_display callback being called
// In this case, I am outputting the image "caption" and the image "description"
// with the excerpt & content filters applied, respectively
if ( ! empty( $image->post_excerpt ) ) {
echo '<div class="photo-credit">';
echo apply_filters( 'the_excerpt', $image->post_excerpt );
echo '</div>';
}
if ( ! empty( $image->post_content ) ) {
echo '<div class="featured-image-caption">';
echo apply_filters( 'the_content', $image->post_content );
echo '</div>';
}
echo '</figcaption>';
// Now, if the callback was registered to begin with, we need to put it back
if ( $sharecontent ) {
add_filter( 'the_content', 'sharing_display', 19 );
}
if ( $shareexcerpt ) {
add_filter( 'the_excerpt', 'sharing_display', 19 );
}
echo '</figure>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment