First paragraph above featured image – possible?

Posted in: Newspaper
Post count: 9

Hi everyone,

I have a question about putting the first paragraph in a blogpost above the featured image. Is this possible to achieve without using plugins, and just make modification to functions.php or similar?

Unfortunately my programmingskills are limited so I hope someone her got the php-kungfu needed to help me.

Best Regards
Daniel

Post count: 1341

You can manually set the first paragraph at the top of any image by using for example Post template Style 5:

https://demo.tagdiv.com/newspaper/td-post-mcdonell-kanye-west-highlights-difficulties-for-celebrities/

https://forum.tagdiv.com/post-templates-2/

Post count: 9

Thank you for the answer. But I have more than 2 000 articles and I can’t add the paragraph manually on each one.

Is there no other way to handle such issue?

Post count: 20688

Hi,

You could try something like this, try this function and see if it works properly
https://napitwptech.com/tutorial/wordpress-development/display-first-paragraph-added-posts-via-wordpress/
The post template files are located in the main theme folder
https://www.screencast.com/t/bfalqBLmR

Thanks

Post count: 9

Thank you Simion for your answer, that looks almost like what I need.

Though, I might have been a bit unclear on my needs. I want to move my featured image between the first and second paragraph (with no manual editing).

Perhaps the code from your linked example, Simion, could be modified to make that work?

Post count: 20688

Hi,

I understand what you are trying to do. But the featured image is not included in the post content so it cannot be moved around, or positioned differently within the actual post content. You can see here for example how a post template structure looks
https://www.screencast.com/t/a4b34gb9
That solution that I found will bring the first paragraph above the featured image
https://www.screencast.com/t/zAFFoj0dg
But the paragraph will still be displayed where it normally does
https://www.screencast.com/t/Eu4MwvqGScFZ
So maybe it could be hidden with a code like this, or similar
https://www.screencast.com/t/9xxucZZDzUmB

.td-post-content p:nth-child(1) {
display:none;
}

Thanks

Post count: 9

Thank you again for the answer,

Your last piece of code almost worked, I just had to change the (1) to (3) and that did the trick!

Before/After: https://imgur.com/a/jT6Er (embedding didn’t work)

.td-post-content p:nth-child(3) {
display:none;
}

(1) The first paragraph was removed from above the image and still shown below as normal.
(2) Nothing happened at all.
(3) First paragraph is shown above the image, and second paragraph is the first on below as I wan’ted it.

Thank you very much for the help. I hope my change to the code helps someone else with similar issue in the future.

Viewing 7 posts - 1 through 7 (of 7 total)
The forum ‘Newspaper’ is closed to new topics and replies.