Cyber Week Sale! Get $20 off GP Premium, $40 off our new Lifetime license, and 45% off license renewals/extensions! Learn more

Hooks: generate_after_entry_content?

Home Forums Support Hooks: generate_after_entry_content?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #175553
    Paul

    Hey Tom.

    I was looking to add a mailchimp form at the end of every post (not page), as an extension of the content. i.e. before the pagination and footer widgets.

    I added the code to the generate_after_content hook via the GP Hooks plugin, and this worked perfectly, adding the content exactly where I wanted it.

    However, it also added this content after every post excerpt on the blog home page.

    Looking at the documentation, it seems there is a generate_after_entry_content hook too? But I can’t see that in the GP Hooks plugin UI.

    Questions:

    1. Will generate_after_entry_content do what I want, including the content ONLY on the entry page (and not the index/excerpts)?

    2. How can I restrict that content to posts only? i.e. not pages.

    #175615
    Tom
    Lead Developer
    Lead Developer

    You would have to use a PHP function to use that hook: https://generatepress.com/knowledgebase/hook-list/

    You can try it in GP Hooks by putting it in a conditional:

    <?php if ( is_single() ) : ?>
        Your code in here
    <?php endif; ?>

    Then check the “Execute PHP” checkbox.

    #175672
    Paul

    Adding the is_single() test worked with the after_content hook, Tom. Thanks!

    Would generate_after_entry_content had worked (in code) without the test? How does that hook differ from the generate_after_content hook?

    #175713
    Tom
    Lead Developer
    Lead Developer

    generate_after_entry_content appears on single post pages above the footer meta (categories, tags etc..).

    You can use this PHP function to add stuff to it:

    add_action( 'generate_after_entry_content', 'generate_add_after_entry_content' );
    function generate_add_after_entry_content()
    { ?>
        Your content/code/whatever in here
    <?php }

    Adding PHP: https://generatepress.com/knowledgebase/adding-php-functions/

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.