add_filter( 'the_content', 'cvp_theme_auto_show_related_custom_posts', 999 );
function cvp_theme_auto_show_related_custom_posts( $content ) {
if ( is_singular( 'CUSTOM_POST_HERE' ) ) {
ob_start();
$paragraphs = explode( '</p>', $content );
$paragraphs_count = count( $paragraphs );
//adonde mostrar
$mostrar=2;
if ($paragraphs_count>4)
{
$new_content = '';
for ( $i = 0; $i < $paragraphs_count; $i++ ) {
if ( $i === $mostrar ) {
// Add custom content in the middle of post contents
$new_content .= '<h3>Related posts</h3>';
$new_content .= do_shortcode( '[pt_view id="VIEW_ID" taxonomy="GET_CURRENT" terms="GET_CURRENT"]' );
}
// Append the missing closing p tag
$new_content .= $paragraphs[ $i ] . '</p>';
}
}
//echo '<h3>Related posts</h3>';
//echo do_shortcode( '[pt_view id="VIEW_ID" taxonomy="GET_CURRENT" terms="GET_CURRENT"]' );
$new_content .= ob_get_clean();
}
return $new_content;
}