Site logo

Archived topic

Redefining generate_blog_post_image?

9 replies · Started by Katie Jones on February 3, 2016

Viewing posts 1–10 of 10

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
}

Hi 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 :)

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 }

Try 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 }

That did it!! Thanks! For next time, how did you know to use priority 20 there?

The 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 :)

Awesome, makes sense. Thank you!

This theme has been a fantastic, clean base for many projects by now - thanks again for a great theme!

Thanks for using it! :)

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.

Thanks for sharing, Jan! :)

This archived topic is closed to new replies.