- This topic has 9 replies, 4 voices, and was last updated 5 years, 7 months ago by
Tom.
-
AuthorPosts
-
February 3, 2016 at 6:31 pm #170258
Katie Jones
Hi,
I’m trying to remove the generate_blog_post_image hook from my theme so I can make a tweak to the code. I grabbed the function from the plugin, and put the following in my functions.php. The result is two images – add_action is adding, but remove_action isn’t removing, with a priority of 1. What am I missing? Thanks!
remove_action( ‘generate_after_entry_header’, ‘generate_blog_post_image’, 1);
add_action( ‘generate_after_entry_header’, ‘hoh_generate_blog_post_image’, 1);function hoh_generate_blog_post_image(){
// code
}February 4, 2016 at 12:11 am #170281Tom
Lead DeveloperLead DeveloperHi Katie,
Try adding the remove action in a function that hooks into after_setup_theme.
add_action( 'after_setup_theme','generate_remove_post_image' ); function generate_remove_post_image() { // remove action code in here. Priority must match add action if it exists. }
Let me know if this helps or not π
February 8, 2016 at 6:11 pm #171429Katie
Hi Tom, thanks!
This isn’t working for me yet.. I’m not sure how to tell what priority remove_action should have so that may be what I’m missing… any ideas? I tried priority 1, that didn’t work. Here’s my code, below. Thanks!
Katie
==
add_action( ‘after_setup_theme’,’generate_remove_post_image’ );
function generate_remove_post_image() {
remove_action( ‘generate_after_entry_header’, ‘generate_blog_post_image’);
}
add_action( ‘generate_after_entry_header’, ‘hoh_generate_blog_post_image’, 1);function hoh_generate_blog_post_image() { //code }
February 9, 2016 at 12:03 am #171460Tom
Lead DeveloperLead DeveloperTry this:
add_action( 'wp','generate_remove_post_image', 20 ); function generate_remove_post_image() { remove_action( 'generate_after_entry_header', 'generate_blog_post_image' ); } add_action( 'generate_after_entry_header', 'hoh_generate_blog_post_image' ); function hoh_generate_blog_post_image() { //code }
February 9, 2016 at 6:09 am #171534Katie
That did it!! Thanks! For next time, how did you know to use priority 20 there?
February 9, 2016 at 11:27 am #171612Tom
Lead DeveloperLead DeveloperThe trick was changing the “after_setup_theme” hook to “wp” which is where the original hook is called.
Then I added 20 so it would fire after the original hook (with doesn’t have a priority, which usually defaults to 10).
So that 20 could be 11, I just chose 20 π
February 9, 2016 at 11:35 am #171615Katie
Awesome, makes sense. Thank you!
This theme has been a fantastic, clean base for many projects by now – thanks again for a great theme!
February 9, 2016 at 11:37 am #171616Tom
Lead DeveloperLead DeveloperThanks for using it! π
November 8, 2017 at 3:17 pm #418904Jan
Hi,
generate_blog_post_image() function is now deprecated (GP Premium 1.5). Therefore, I am using this approach instead:
add_filter( 'generate_featured_image_output', 'my_featured_image_output' ); function my_featured_image_output(){ return [something]; }
The related code is in ./gp-premium/blog/functions/images.php.
Hope this helps.
November 8, 2017 at 3:18 pm #418905Tom
Lead DeveloperLead DeveloperThanks for sharing, Jan! π
-
AuthorPosts
- You must be logged in to reply to this topic.