loader spinner

Can you override a plugin function?

December 12, 2019 11:27am - 1 min read

Last updated on: April 01, 2020 3:10am

if the original plugin author added a add_filter() or add_cation() to the original function then its possible to change plugin function targeting that filter or action.

You can’t really override a function. If a function is defined, you can’t redefine or change it. Your best option is to create a copy of the plugin and change the function directly. Of course you will have to repeat this every time the plugin is updated.

For example: a plugin has following function

function keenDevs(){
// logics here
}

You can’t override this function. Period.

But if function is defined like this:

add_action('wp_head','add_gpp_gallery');
function add_gpp_gallery() {
// logics here
}

Now you can override. First you have to remove the action and then use your custom function.

remove_action( 'wp_head', 'add_gpp_gallery' );
add_action('wp_head','keenDevs_add_gpp_gallery');
function keenDevs_add_gpp_gallery() {
// Your custom logics here
}

 

Last updated on: April 01, 2020 3:10am