Black Friday Sale! Get up to $40 off GP Premium!Learn more

[Resolved] Redefining generate_blog_post_image?

Home Forums Support Redefining generate_blog_post_image?

  • This topic has 9 replies, 4 voices, and was last updated 3 years ago by Tom.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #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
    }

    #170281
    Tom
    Lead Developer
    Lead Developer

    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 🙂

    #171429
    Katie

    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 }

    #171460
    Tom
    Lead Developer
    Lead Developer

    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 }
    #171534
    Katie

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

    #171612
    Tom
    Lead Developer
    Lead Developer

    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 🙂

    #171615
    Katie

    Awesome, makes sense. Thank you!

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

    #171616
    Tom
    Lead Developer
    Lead Developer
    #418904
    Jan

    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.

    #418905
    Tom
    Lead Developer
    Lead Developer
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.