Site logo

Archived topic

Featured Image after first paragraph

7 replies · Started by Vish on April 12, 2018

Viewing posts 1–8 of 8

Hello!

How to make the featured image appear after the first paragraph in the posts?

Thanks!

Hi Tom,
If I want to appear it to after 3 paragraphs, then what should I change in above code.

Thanks, David

You're welcome

Is it possible to exclude pages with the function that Tom suggested?

Hi there,

you would need to include a template tag condition to the rule - for example:

add_filter( 'the_content', 'insert_featured_image', 20 );

function insert_featured_image( $content ) {
    if ( !is_page() ) {
        $content = preg_replace( "/<\/p>/", "</p>" . get_the_post_thumbnail($post->ID, 'post-single'), $content, 1 );
    }
    return $content;
}

This will only add the featured image IF ITS NOT a Page.

This archived topic is closed to new replies.