[Resolved] Element not Showing with generate_after_entry_content hook

Home Forums Support [Resolved] Element not Showing with generate_after_entry_content hook

Home Forums Support Element not Showing with generate_after_entry_content hook

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1633247
    Samuel

    I have a GP element that I want to show on a specific page. If I used the hook generate_after_content it works, but if I use the hook generate_after_entry_content it does not display. I cannot figure out why it’s not showing? this must be obvious but I’m lost.

    #1633490
    Elvin
    Staff
    Customer Support

    Hi there,

    There’s no generate_after_entry_content hook for pages. You can check it here:
    https://github.com/tomusborne/generatepress/blob/master/content-page.php

    That’s only for single posts pages as found here:
    https://github.com/tomusborne/generatepress/blob/e030f57d2c26991074a6868265737424dac567d0/content-single.php#L92

    #1633516
    Samuel

    Ah. Thanks I never realized pages and posts had different hooks 🤦🏻‍♂️

    #1633527
    Elvin
    Staff
    Customer Support

    No problem. 🙂

    #1666712
    acela

    > “There’s no generate_after_entry_content hook for pages.”

    Hi, wondering if there’s a specific rationale for this? The reason I ask is because pages have the entry_content div too…

    If the generate_after_entry_content hook worked for both posts and pages, then we could control display on either or both via the hook’s Display Rules.

    What I would like is my content to appear before the categories & tags on posts, but also at the bottom of all pages.

    So do I have to use 2 different hooks to achieve this with the same content? (or maybe I’m missing something)

    Thanks!

    #1667134
    Elvin
    Staff
    Customer Support

    generate_after_entry_content is mainly used for hooking in the footer meta for post pages as shown here:
    https://github.com/tomusborne/generatepress/blob/7b35168f546f83a7abb098a8da3bc0674d49ddeb/inc/structure/post-meta.php#L525

    It’s quite difficult to change it now as there’s no telling how many users site’s are going to be affected by the change but aside from what I mentioned, this hook is basically the same as generate_after_content.

    So do I have to use 2 different hooks to achieve this with the same content? (or maybe I’m missing something)

    Yeah you basically have to use 2 Hook Elements. 1 for the post page generate_after_entry_content if you want to make something appear before the footer meta as you’ve linked.

    And the other one, generate_after_content for the static pages.

    #1667149
    acela

    Hey Elvin, thanks for the further details.

    I see what you say that it’s used for hooking in the footer meta for posts, but there’s nothing about the hook itself that confines it to that usage… As entry_content divs are an integral part of pages as well as posts, I was surprised to see the hook’s presence on posts only – one would think it should apply to pages as well.

    You’re right of course about folks out there already using it, but everyone needs to already specify where the hook will fire in the Display Rules. In other words, offering the option to apply to pages as well as posts wouldn’t affect everyone who already set their Display Rules for posts.

    For now I will duplicate the content across two separate hooks, but it might be worth revisiting this one.

    Thanks again for your assistance!

    #1667310
    Elvin
    Staff
    Customer Support

    If you really need it you can make a page template yourself with child themes.

    You can copy the code of content-page.php and paste it on your new template page.php

    And place this code –

    		/**
    		 * generate_after_entry_content hook.
    		do_action( 'generate_after_entry_content' );
    
    		/**
    		 * generate_after_content hook.
    		 *
    		 * @since 0.1
    		 */

    Before the do_action( 'generate_after_content' ); to add the hook.

    It’s actually a good point. It brings uniformity to hooks.

    For now, It’s not within the immediate updates in mind especially when a new GP update is about to drop.(early or mid March, GP 3.1.0)

    No problem. 🙂

    #1667490
    Samuel

    I understand the various considerations, but I agree with @acela it would be helpful to have uniformity to these hooks.

    #1667891
    acela

    Thanks Samuel and Elvin; glad you’ll consider it further.

    Using a child theme is a possibility, but I’m trying to avoid that as it makes GP/GPP theme updates more involved and time-consuming to review & integrate if any changes were made to the file in question.

    Thank you again!

    #1667895
    David
    Staff
    Customer Support

    Hi there,

    you can unhook the post meta and hook it back in to the after_content hook:

    add_action( 'wp', function() {
      remove_action( 'generate_after_entry_content', 'generate_footer_meta' );
      add_action( 'generate_after_content', 'generate_footer_meta', 25 );
    } );
    #1667929
    acela

    Very interesting, thanks David!

    I normally wouldn’t be inclined to restructure GP’s hooks, but that is a clever alternative to a child theme.

    #1668011
    David
    Staff
    Customer Support

    You’re welcome

    #1668089
    Tom
    Lead Developer
    Lead Developer

    Yea, this was an oversight a long time ago that is hard to solve now. We could easily add the hook into the next update, but that runs the risk of causing changes when someone updates if they’re currently using generate_after_entry_content without conditions and are used to it only working on posts.

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