Archived topic
Featured Image after first paragraph
7 replies · Started by Vish on April 12, 2018
Hello!
How to make the featured image appear after the first paragraph in the posts?
Thanks!
You could try:
1. Disabling the featured image in Customize > Layout > Blog.
2. Adding a function like this: https://wordpress.stackexchange.com/a/61280
Hi Tom,
If I want to appear it to after 3 paragraphs, then what should I change in above code.
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
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.