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 9 years, 3 months ago by
Shea Bunge.
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?
Hi Amber,
This looks like it’s a different issue. Would you mind starting a new thread?
-
This reply was modified 9 years, 2 months ago by
Shea Bunge.
Hey Amber,
Are you still experiencing this problem? Which theme are you using, specifically, so I can take a look at it?