[Resolved] Redefining generate_blog_post_image?

Home Forums Support [Resolved] Redefining generate_blog_post_image?

Home Forums Support Redefining generate_blog_post_image?

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

    Thanks for using it! πŸ™‚

    #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

    Thanks for sharing, Jan! πŸ™‚

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