I'm using a plugin. It has an action like this.

add_action('publish_post', 'old_action');
function old_action($pid) {
    "code goes here"

I'm writing a module for this plugin. So i need to override that old action function with my new action function.

This is my new function.

function new_action($pid) {
      "code goes here"

I want to replace that old_action function with my new_action function using hooks. Can anyone help me?



You can use the remove_action() function, like this:

remove_action('publish_post', 'old_action');
add_action('publish_post', 'new_action');

It's important to note that if the old_action was added with a priority parameter, you must add that to the remove_action call, otherwise it will fail to remove it. There are other implications if the old_action was added within a class. See here for more info.

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.