- This topic has 13 replies, 5 voices, and was last updated 3 years, 1 month ago by Tom.
-
AuthorPosts
-
January 25, 2021 at 11:51 am #1633247Samuel
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.
January 25, 2021 at 6:04 pm #1633490ElvinStaffCustomer SupportHi 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.phpThat’s only for single posts pages as found here:
https://github.com/tomusborne/generatepress/blob/e030f57d2c26991074a6868265737424dac567d0/content-single.php#L92January 25, 2021 at 6:52 pm #1633516SamuelAh. Thanks I never realized pages and posts had different hooks 🤦🏻♂️
January 25, 2021 at 7:06 pm #1633527ElvinStaffCustomer SupportNo problem. 🙂
February 21, 2021 at 8:49 am #1666712acela> “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!
February 21, 2021 at 8:23 pm #1667134ElvinStaffCustomer Supportgenerate_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#L525It’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.February 21, 2021 at 8:50 pm #1667149acelaHey 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!
February 22, 2021 at 1:08 am #1667310ElvinStaffCustomer SupportIf 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.phpAnd 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. 🙂
February 22, 2021 at 4:09 am #1667490SamuelI understand the various considerations, but I agree with @acela it would be helpful to have uniformity to these hooks.
February 22, 2021 at 7:17 am #1667891acelaThanks 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!
February 22, 2021 at 7:22 am #1667895DavidStaffCustomer SupportHi 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 ); } );
February 22, 2021 at 7:49 am #1667929acelaVery interesting, thanks David!
I normally wouldn’t be inclined to restructure GP’s hooks, but that is a clever alternative to a child theme.
February 22, 2021 at 8:50 am #1668011DavidStaffCustomer SupportYou’re welcome
February 22, 2021 at 9:56 am #1668089TomLead DeveloperLead DeveloperYea, 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. -
AuthorPosts
- You must be logged in to reply to this topic.