- This topic has 11 replies, 2 voices, and was last updated 2 years, 7 months ago by David.
-
AuthorPosts
-
September 8, 2021 at 4:53 am #1922796Berto
Hi there,
I’m developing a child theme where I want to have my own author box. For that purpose I want to remove the footer tags completly.
Following your documentation on similar problems and analyzing the code of the parent theme, this snippet should work:
add_action(‘after_setup_theme’, function () {
remove_action(‘generate_after_entry_content’,’generate_footer_meta’);
}… but it doesn’t
Why? How can I get it to work?
Thanks in advance,
BertoSeptember 8, 2021 at 8:39 am #1923168DavidStaffCustomer SupportHi there,
try:
add_action( 'wp', function() { remove_action( 'generate_after_entry_content', 'generate_footer_meta' ); } );
September 8, 2021 at 9:00 am #1923202BertoThat worked, awesome!
By the way, what is the reason it does work this way but not the other way (may be of interest to other people too).
Kind Regards,
BertoSeptember 8, 2021 at 9:09 am #1923207DavidStaffCustomer SupportHooks are fired in a set sequence – you can see them here:
https://codex.wordpress.org/Plugin_API/Action_Reference
Some of the hooks in GP like
generate_after_entry_content
are fired after theafter_setup_theme
is fired.
So by moving to the WP hook allows us to override any changes made earlier.September 8, 2021 at 9:15 am #1923213BertoOk thank you for your response!
September 9, 2021 at 2:45 am #1923947DavidStaffCustomer SupportYou’re welcome
September 9, 2021 at 2:56 am #1923958BertoHi again,
Finally, for a clean solution, I will need to remove the meta entry header (… class=”entry-meta” …) and build it by myself.
I tried out this:
remove_action( ‘wp’, ‘generate_add_post_meta’, 5 );
And this:
remove_action( ‘generate_after_entry_title’, ‘generate_post_meta’);
Both it didn’t work
How can I achive this and what hook would you recommend using for rebuilding it with my own code?
Thanks in advance,
BertoSeptember 9, 2021 at 3:55 am #1924005DavidStaffCustomer SupportYou can update the code i provided to remove both:
add_action( 'wp', function() { remove_action( 'generate_after_entry_title', 'generate_post_meta' ); remove_action( 'generate_after_entry_content', 'generate_footer_meta' ); } );
September 9, 2021 at 7:17 am #1924198BertoNow it worked!
The strange thing is that I already had it within the add_action(‘wp’… function, but I guess that I got muddled with something π
Thank you again!
BertoSeptember 9, 2021 at 8:06 am #1924455DavidStaffCustomer SupportI think i did a terrible job of explaining Hooks and there order lol
A very simplified example of how things load:
1. WordPress Init and some other stuff ( including the
after_setup_theme hook
) is executed.
… some other stuff happens
2. WordPress then reaches thewp
function and one of its functions is to load the correct template files eg. single.php for the page being viewed.
Inside our template we have our Hooks registered eg.do_action('generate_after_entry_title'); // some other code here do_action('generate_after_entry_content');
… some other stuff happens
3. Then Later on the Theme or GPP adds a callback to those hooks
add_action( 'the_hook', 'the_callback');
eg.add_action( 'generate_after_entry_title', 'generate_post_meta' );
4. WordPress continues running other functions hooked into
wp
plus some other stuff.So by doing this:
add_action( 'wp', function() { // Do some stuff } );
We
Do some stuff
after steps #1, #2 and #3 are finished.Whereas this hook gets fired before #2 ( and #3 ):
add_action( 'after_setup_theme', function() { // Do some stuff } );
So our remove_action is fired before step #3, and then later on GPP is adding something back in π
September 9, 2021 at 9:55 am #1924596BertoWow! That was an awesome explanation!
I’m learning a lot with your help π
Thanks again!
BertoSeptember 9, 2021 at 12:13 pm #1924714DavidStaffCustomer SupportGlad to hear that !!!
-
AuthorPosts
- You must be logged in to reply to this topic.