Archived topic
displaying featured image after 2nd paragraph
5 replies · Started by dassana on December 26, 2019
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 );
}
}
Hi there,
Where did you get the code?
Have you checked with the author of the code?
This isn't part of the theme.
i got it from the web. it is not a part of the theme. is there any other code for the theme.
Might need to check with whoever created the code.
Or maybe try changing the 1 in the second function to 2?
Not sure if it will work but worth a shot.
thanks. i will try.
No problem :)