- This topic has 9 replies, 3 voices, and was last updated 2 years, 11 months ago by David.
-
AuthorPosts
-
March 4, 2021 at 6:22 am #1681730Susan
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
March 4, 2021 at 7:29 am #1681998DavidStaffCustomer SupportHi 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.March 4, 2021 at 7:46 am #1682043SusanIs 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
March 4, 2021 at 7:51 am #1682047DavidStaffCustomer SupportIn 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 πMarch 4, 2021 at 7:57 am #1682057SusanThanks, that worked perfectly!
Have a good day π
March 4, 2021 at 7:57 am #1682060DavidStaffCustomer SupportYou’re welcome – and you too!
May 11, 2021 at 2:03 am #1773814CRAIGThis 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
May 11, 2021 at 2:09 am #1773818DavidStaffCustomer SupportHi 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
May 11, 2021 at 2:46 am #1773857CRAIGAwesome 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
May 11, 2021 at 3:08 am #1773879DavidStaffCustomer SupportWould you mind starting a new topic – so as not to bog down the OP with notifcations π
-
AuthorPosts
- You must be logged in to reply to this topic.