hi tom
currently, i am showing featured image after first paragraph. i am using the code pasted below. What changes should be done in the code so that the featured image gets displayed after the second paragraph.
function prefix_insert_after_paragraph2( $ads, $content ) {
if ( ! is_array( $ads ) ) {
return $content;
$paragraphs = explode( $closing_p, $content );
foreach ($paragraphs as $index => $paragraph) {
if ( trim( $paragraph ) ) {
$paragraphs[$index] .= $closing_p;
}
$n = $index + 1;
if ( isset( $ads[ $n ] ) ) {
$paragraphs[$index] .= $ads[ $n ];
}
}
return implode( '', $paragraphs );
}
add_filter( 'the_content', 'insert_featured_image' );
function insert_featured_image ( $content ) {
$content = prefix_insert_after_paragraph2( array(
// The format is: '{PARAGRAPH_NUMBER}' => 'AD_CODE',
'1' => get_the_post_thumbnail( get_the_ID(), 'post-single', array( 'class' => 'aligncenter' ) ),
), $content );
}
}