[Support request] Pushing the Featured Image Down Past The Second Paragraph

Home Forums Support [Support request] Pushing the Featured Image Down Past The Second Paragraph

Home Forums Support Pushing the Featured Image Down Past The Second Paragraph

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1681730
    Susan

    Hello,

    I am looking for a way to show the featured images on the blog page, but have the featured image show only after the second paragraph.

    I tried adding the following code below to the functions page, and it shows the image after the second paragraph, but the featured image is still showing at the top before the heading. I don’t want it showing up before the heading only once after the second paragraph.

    add_filter( ‘the_content’, ‘insert_featured_image’, 20 );
    function insert_featured_image( $content ) {
    $feat_img = get_the_post_thumbnail($post->ID, ‘post-single’);
    if ( is_single() && ! is_admin() ) {
    return prefix_insert_after_paragraph( $feat_img, 2, $content );
    }
    return $content;
    }
    // Parent Function that makes the magic happen
    function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) {
    $closing_p = ‘</p>’;
    $paragraphs = explode( $closing_p, $content );
    foreach ($paragraphs as $index => $paragraph) {
    if ( trim( $paragraph ) ) {
    $paragraphs[$index] .= $closing_p;
    }
    if ( $paragraph_id == $index + 1 ) {
    $paragraphs[$index] .= $insertion;
    }
    }
    return implode( ”, $paragraphs );
    }

    I’ve looked everywhere and have been unable to find a solution. Any help would be greatly appreciated.

    Thanks

    Susan

    #1681998
    David
    Staff
    Customer Support

    Hi there,

    go to Customizer > Layout > Blog –> Featured Image >> Posts and uncheck: Display featured images
    This will remove the one added by the Theme – it won’t affect the one added by that code.

    #1682043
    Susan

    Is there a way to still show thumbnails on the blog page without showing the featured image after the heading? If uncheck the featured image, my blog page has no images, which looks weird.

    In a perfect world, I can show an image on the blog page and the featured image shows up after the second paragraph.

    I’m sure it’s not possible but thought I’d ask.

    Thanks

    #1682047
    David
    Staff
    Customer Support

    In the Featured Image settings:

    https://docs.generatepress.com/article/adjusting-the-featured-images/

    You have the option to Display or Not display the featured image for Archives, Posts and Pages.
    You just want to uncheck the option for Posts πŸ™‚

    #1682057
    Susan

    Thanks, that worked perfectly!

    Have a good day πŸ™‚

    #1682060
    David
    Staff
    Customer Support

    You’re welcome – and you too!

    #1773814
    Craig

    This is exactly what I require as I too want to move the featured image to after the second paragraph

    However, when pasting in this code snippet (being posted on a public forum I take it you don’t mind it being used) I get the following errors:

    Parse Error : syntax error, unexpected ‘/’ on line 11
    Parse Error : syntax error, expected ‘p’ (T_STRING), expecting ‘;’

    Any chance you could suggest a way to resolve this?

    I am not a programmer and tend to stay away from adding snippets, but this appears to be the only way I can get the featured image to move to where I’d like it to be.

    Thanks

    Craig

    #1773818
    David
    Staff
    Customer Support

    Hi there,

    thats because the code above was added in the normal editor and not a code block.
    You can copy the code from one of the original topics here:

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

    #1773857
    Craig

    Awesome thank you, this works perfectly.

    It would also be useful for me to be able to add my table of contents to after the featured image.

    Do you have any pointers on how to do that?

    I am using the “Easy table of contents” plugin which has an option to change the position of the table, but it is limited to ‘before the first heading’, ‘after the first heading, ‘top’, and ‘bottom’.

    I originally had it in the sidebar as a widget, however, this is not ideal for mobile users and I’d like to have it appearing just after the featured image

    #1773879
    David
    Staff
    Customer Support

    Would you mind starting a new topic – so as not to bog down the OP with notifcations πŸ™‚

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