[Resolved] Is there a hook after page's featured image?

Home Forums Support [Resolved] Is there a hook after page's featured image?

Home Forums Support Is there a hook after page's featured image?

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #335764
    Katie 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!

    #335765
    Katie Jones

    (for my own reference too) – I found this, though don’t see a hook that’s what I’m looking for:

    http://demo.generatepress.com/hook-locations/

    #335776
    Tom
    Lead Developer
    Lead Developer

    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
    }
    #335788
    Katie Jones

    That did it, thank you!

    #335868
    Tom
    Lead Developer
    Lead Developer

    You’re welcome ๐Ÿ™‚

    #514015
    Henrik

    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!

    #514057
    Leo
    Staff
    Customer Support

    Not sure what you mean by overlay on featured image?

    Can you please open a new topic?

    Thanks!

    #514406
    Henrik

    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.

    #514825
    Leo
    Staff
    Customer Support

    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!

    #524468
    Paul

    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

    #524657
    Leo
    Staff
    Customer Support

    Hi Paul,

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

    Thanks!

    #524670
    Henrik

    Hi Paul,

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

    #525530
    Paul

    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.

    #525561
    Henrik

    Hi Paul,

    thanks for the code. Unfortunately for me this ends up showing the text above the headline ๐Ÿ™

    #525570
    Paul

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

Viewing 15 posts - 1 through 15 (of 19 total)
  • The topic ‘Is there a hook after page's featured image?’ is closed to new replies.