Site logo

Archived topic

Hooks: generate_after_entry_content?

3 replies · Started by Paul on February 26, 2016

Viewing posts 1–4 of 4

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.

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.

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?

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/

This archived topic is closed to new replies.