WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question
up vote 17 down vote accepted

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.

share|improve this answer
+1 with the clarification that the remove action must be called after the function it is removing is added. – Stephen Harris Jan 28 '12 at 8:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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