[Resolved] displaying featured image after 2nd paragraph

Home Forums Support displaying featured image after 2nd paragraph

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1114592
    dassana

    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 );
     }
    }
    #1114593
    Leo
    Staff
    Customer Support

    Hi there,

    Where did you get the code?

    Have you checked with the author of the code?

    This isn’t part of the theme.

    #1114598
    dassana

    i got it from the web. it is not a part of the theme. is there any other code for the theme.

    #1114617
    Leo
    Staff
    Customer Support

    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.

    #1114619
    dassana

    thanks. i will try.

    #1114777
    Leo
    Staff
    Customer Support
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.