Site logo

Archived topic

Is there a hook after page's featured image?

18 replies · Started by Katie Jones on June 19, 2017

Viewing posts 1–15 of 19

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!

Hi 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
}

That did it, thank you!

You're welcome :)

Hi 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!

Not sure what you mean by overlay on featured image?

Can you please open a new topic?

Thanks!

Hi 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.

Can 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!

Hi 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

Hi Paul,

Can you open a new topic for your question and possibly link us to your site?

Thanks!

Hi Paul,

I encountered exactly the same problem without finding a solution. So I'm also very interested in finding out how to manage.

I 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.

Hi Paul,

thanks for the code. Unfortunately for me this ends up showing the text above the headline :-(

Yes, for me too, above the headline and below the featured image. That's what I needed. Where do you need it to show?

This archived topic is closed to new replies.