Site logo

[Support request] Inserting Featured Image Inside First Blockquote

Home Forums Support [Support request] Inserting Featured Image Inside First Blockquote

Home Forums Support Inserting Featured Image Inside First Blockquote

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1905998
    Allan

    Hi Guys,

    Sorry, this is a bit of a weird request but it would certainly help a specific issue I have.

    Is it possible to have a CSS code to insert the feature image into the first blockquote similar to moving the feature image down to after a paragraph?

    Thanks
    Allan

    #1906077
    Elvin
    Staff
    Customer Support

    Hi Allan,

    Can you provide any mockup image of how you want things to be laid out?

    How will the feature image fit? Will it be a background image? Or perhaps an actual element on the blockquote layout?

    Let us know. 😀

    #1906212
    Allan

    Sent info privately

    #1906515
    David
    Staff
    Customer Support

    Hi there,

    injecting the image within the blockquote is tricky, not something i have a solution for, it’ll probably require regex which blows my brain lol. Closes thing would be to insert it after the Blockquote:

    add_filter( 'the_content', 'insert_featured_image', 20 );
    function insert_featured_image( $content ) {
        global $post;
        $feat_img = get_the_post_thumbnail($post->ID, 'post-single');
        if ( is_single() && ! is_admin() ) {
            return prefix_insert_after_paragraph( $feat_img, 1, $content );
        }
        return $content;
    }
    // Parent Function that makes the magic happen
    function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) {
        $closing_p = '</blockquote>';
        $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 );
    }
    #1906578
    Allan

    No worries guys.

    Thanks for your support

    #1906636
    David
    Staff
    Customer Support

    You’re welcome

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