[Resolved] Featured Image after first paragraph

Home Forums Support [Resolved] Featured Image after first paragraph

Home Forums Support Featured Image after first paragraph

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #548873
    Vish

    Hello!

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

    Thanks!

    #548966
    Tom
    Lead Developer
    Lead Developer

    You could try:

    1. Disabling the featured image in Customize > Layout > Blog.

    2. Adding a function like this: https://wordpress.stackexchange.com/a/61280

    #1472588
    Immi

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

    #1472691
    David
    Staff
    Customer Support

    Hi there,

    try the method provided here:

    https://generatepress.com/forums/topic/featured-image-inside-the-article/#post-708308

    In that function you will see this line:

    return prefix_insert_after_paragraph( $feat_img, 2, $content );

    Change the 2 to 3

    #1473214
    Immi

    Thanks, David

    #1473275
    David
    Staff
    Customer Support

    You’re welcome

    #1770458
    Liran

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

    #1770541
    David
    Staff
    Customer Support

    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.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.