- This topic has 18 replies, 1 voice, and was last updated 3 years, 5 months ago by impro1.
-
AuthorPosts
-
June 19, 2017 at 9:57 am #335764Katie Jones
Hi there –
I want to insert html below the featured image, full width (so not in the content area, since I’m using a sidebar). Is there a hook I can use to do that?
Thanks!
June 19, 2017 at 9:58 am #335765Katie Jones(for my own reference too) – I found this, though don’t see a hook that’s what I’m looking for:
June 19, 2017 at 10:11 am #335776TomLead DeveloperLead DeveloperHi Katie,
The featured image is hooked into the generate_after_header hook by default.
So you can hook into the same area with a higher priority and it will display after it:
add_action( 'generate_after_header', 'tu_after_featured_image', 15 ); function tu_after_featured_image() { ?> Your content in here <?php }
June 19, 2017 at 11:06 am #335788Katie JonesThat did it, thank you!
June 19, 2017 at 2:35 pm #335868TomLead DeveloperLead DeveloperYou’re welcome ๐
March 7, 2018 at 8:33 am #514015HenrikHi Tom,
I also tried to insert html below the featured image with the above solution but unfortunately it didn’t word. The content appeared after the header. So I tried to hook it in “after entry title hook” which is quiet close as it appears above the featured image but not below.
For copyright reasons I tried to display the featured image description with the following code in “after entry title hook”:
<?php
if (get_post(get_post_thumbnail_id())->post_excerpt) { // search for if the image has caption added on it ?>
<span class=”featured-image-caption”>
<?php echo wp_kses_post(get_post(get_post_thumbnail_id())->post_excerpt); // displays the image caption ?>
</span>
<?php } ?>How could I get this below the featured image or as an overlay on the featured image?
Thanks in advance for your help!
March 7, 2018 at 9:35 am #514057LeoStaffCustomer SupportNot sure what you mean by overlay on featured image?
Can you please open a new topic?
Thanks!
March 7, 2018 at 11:46 pm #514406HenrikHi Leo,
overlay was just nice to have. Mainly I want to insert html below the featured image like Katie but the solution provided above doesn’t work.
March 8, 2018 at 8:45 am #514825LeoStaffCustomer SupportCan you open a new topic and link us to your site?
You probably have different layout then Katie so will have to modify the code.
Thanks!
March 20, 2018 at 6:48 am #524468PaulHi Tom, I also want to hook in after a post’s featured image. I’ve tried adding the code below to the after header hook in GP hooks, and I checked execute PHP:
<?php add_action( 'generate_after_header', 'tu_after_featured_image', 15 ); function tu_after_featured_image() { echo 'Your content in here'; } ?>
When I do that though, the ‘Your content in here’ shows before the featured image, and not after it. It doesn’t matter which priority I set, I tried 1 and 99, same result – the text is before the featured image always.
I also tried adding the same code snippet to my functions.php which did nothing.
Am I missing or misunderstanding something here?
How can I make this solution work?
For clarity’s sake, here’s a screenshot of exactly what I’m trying to do: https://cl.ly/463g0t3t1j0q
March 20, 2018 at 9:24 am #524657LeoStaffCustomer SupportHi Paul,
Can you open a new topic for your question and possibly link us to your site?
Thanks!
March 20, 2018 at 9:33 am #524670HenrikHi Paul,
I encountered exactly the same problem without finding a solution. So I’m also very interested in finding out how to manage.
March 21, 2018 at 8:55 am #525530PaulI figured it out myself. You can use either of the 2 below code snippets, putting one of them in your functions.php:
add_action( 'generate_before_entry_title', 'tu_after_featured_image', 15 ); function tu_after_featured_image() { ?> Your plain text or HTML content in here <?php } // Or... add_action( 'generate_before_entry_title', 'tu_after_featured_image', 15 ); function tu_after_featured_image() { echo 'Your content in here'; }
All I changed was the hook, from generate_after_header before to generate_before_entry_title now. Now it works, the content is inserted directly after the featured image.
March 21, 2018 at 9:36 am #525561HenrikHi Paul,
thanks for the code. Unfortunately for me this ends up showing the text above the headline ๐
March 21, 2018 at 9:47 am #525570PaulYes, for me too, above the headline and below the featured image. That’s what I needed. Where do you need it to show?
-
AuthorPosts
- The topic ‘Is there a hook after page's featured image?’ is closed to new replies.