Code Snippet: Remove Jetpack Related Posts from Woo Testimonials

When using the Woo Testimonials shortcode, the Jetpack Related Posts module automatically adds the related posts at the end of the testimonial shortcode. We don’t want that, we want to display the related posts at the end of the actual post content.

Code Snippet

/**
 * Remove Jetpack Related Posts from Woo Testimonials shortcode
 * 
 * @see https://jetpack.me/support/related-posts/customize-related-posts/#delete
 *
 * @param string $content
 * @return string $content
 */
function fleeds_jetpackme_remove_rp( $content ) {
 
 // Get the Jetpack Related Posts instance
 $jprp = Jetpack_RelatedPosts::init();
 $callback = array( $jprp, 'filter_add_target_to_dom' );
 
 // Only remove it from the woo_testimonials the_content filter
 if ( 'testimonial' === get_post_type() ) {
 remove_filter( 'the_content', $callback, 40 );
 }
 
 return $content;
}
add_filter( 'the_content', 'fleeds_jetpackme_remove_rp', 20 );

Check out the gist for this code snippet.

Leave a comment

Your email address will not be published. Required fields are marked *

%d bloggers like this: