Archived topic
Inserting Featured Image Inside First Blockquote
5 replies · Started by Allan on August 23, 2021
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
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. :D
Sent info privately
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 );
}
No worries guys.
Thanks for your support
You're welcome