5

I am using a plugin that has this line of code to add an action from the Eazyest_Frontend class:

add_action( 'eazyest_gallery_thumbnails', 'ezg_thumbnails',5);

I want to remove that and do something a bit different without editing the plugin. I thought this added to my functions.php file might work:

global $eazyest_frontend;    
remove_action( 'eazyest_gallery_thumbnails', array($eazyest_frontend,'ezg_thumbnails'), 1, 1 );

I have maybe tried a hundred variations where I altered the priority etc but nothing works yet.

If I comment out the original add action line in the plugin, it does have the effect I am seeking so I seem to have identified the correct action.

I'm new to removing actions, how is it done?

  • 1
    Have you read this? – fuxia Apr 18 '13 at 11:26
  • I was hoping it maybe a bit simpler than that example - from the codex it looks like it's just two lines. I was using the example here also: wordpress.stackexchange.com/questions/75130/… – Steve Apr 18 '13 at 11:57
  • 1
    Add a link to the code of that plugin to your question. There might be an easier way. – fuxia Apr 18 '13 at 11:59
  • Was the plugin initialized as a global variable? – helgatheviking Apr 18 '13 at 12:08
5

Maybe I got you wrong, but why don't you just put the following line in your functions.php:

remove_action('eazyest_gallery_thumbnails', 'ezg_thumbnails');

If you have a class function hooked to an action, you can use the class name instead of the class object:

remove_action(
    'eazyest_gallery_thumbnails',
    array('EazyestFrontendClassName', 'ezg_thumbnails')
);

Right now, I don't see why this wouldn't be working. Just tried with an action from one of my plugins.

2

Similar technique can be used to hide unwanted admin notices.

Find the name of the function creating the notice you want to remove, then add the following line to your child theme's functions.php file:

remove_action( 'admin_notices', 'offending_function_that_is_creating_the_notice' );

Now, only that specific nag will be hidden while other (potentially important) notices from that plugin still get through. This will remain effective through future updates unless the plugin developer modifies the name of the function creating the nag (unlikely).

1

Thanks for all comments and answers - I just solved this:

function remove_eazyest_gallery() {
remove_action('eazyest_gallery_thumbnails',     'ezg_thumbnails', 5);
}
add_action( 'eazyest_gallery_ready', 'remove_eazyest_gallery', 1 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.