• Resolved sanderpinkse

    (@sanderpinkse)


    I’m trying out Code Snippets, and really like it so far! Everything works as expected, except for one thing: it seems that using remove_action in a snippet doesn’t work for me. For instance

    remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );

    doesn’t do anything.

    If I use it in functions.php, it works fine. I’m using a Genesis theme, as you can see above.

    Cheers!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Using remove_action can be tricky, as it needs to be called after the call to add_action has run, but before the action hook itself is applied.

    The reason what works in functions.php doesn’t work in Code Snippets is that snippets run before the theme does, so essentially you are trying to remove an action that has not been added yet.

    Fortunately, there is a simple fix for this, which is to wrap your call to remove_action in an action filter hook:

    add_action( 'init', function () {
    	remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
    } );
    • This reply was modified 7 years, 8 months ago by Shea Bunge.
    Thread Starter sanderpinkse

    (@sanderpinkse)

    Ah! That makes sense. Thanks a lot for the quick response!

    I’m just going to jump in on this.

    How would we handle this if we wanted to use a snippet that adds something to the theme vs. taking it away, or would it be a similar process. For example, I’m testing out some of the default Beaver Builder theme actions like this:

    function my_before_header() {
        echo '<div> I am right before the header div. </div>'; 
    } 
    add_action( 'fl_before_header', 'my_before_header' );

    Those don’t work in Code Snippets but do work in functions.php. What would be the best way to get these to work?

    Plugin Author Shea Bunge

    (@bungeshea)

    Hi Amber,

    This looks like it’s a different issue. Would you mind starting a new thread?

    • This reply was modified 7 years, 8 months ago by Shea Bunge.
    Plugin Author Shea Bunge

    (@bungeshea)

    Hey Amber,

    Are you still experiencing this problem? Which theme are you using, specifically, so I can take a look at it?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Some snippets not working’ is closed to new replies.