Using Remove Action in WordPress

Here’s another microblog for you, how to remove something that has already been added in another plugin using the add_action.

The specific example I have for you is the disqus comment javascript that normally gets added into the wp_footer using the following code:

add_action( 'wp_footer', 'dsq_output_footer_comment_js' );

To remove this, we could go and remove the add_action within the disqus plugin, however this is not a very good idea as it would mean we are editing someone else’s plugin that would be overwritten when we upgrade it through wordpress. Instead a better way is to use a Remove Action within our own plugin like so:

remove_action( 'wp_footer', 'dsq_output_footer_comment_js' );

With the above code we are disabling the script from running without having to edit the plugin file itself.

There is always a possibility that through an update the actual function name will change (dsq_output_footer_comment_js) – this is something that we have limited control over but is well worth keeping an eye on. Therefore whenever we upgrade a plugin that we have adjusted using the remove_action method we should just double check that our removal still works.