How to update plugin without overwrite custom code

i just wanted know that how can i update the plugin without overwrite
the my previous custom code.

You don’t.

Well, you do the same thing over and over and over again every time you want to update.

  1. Download the plugin.
  2. Hack your changes into it.
  3. Upload to your site.
  4. Repeat.

Which is why you don’t edit plugins that you didn’t write and don’t maintain.

The plugin might contain an action or a filter that you can use, but I don’t know about this particular plugin.

There is another option in your case, I am pretty sure. Your function name is HSA_shortcode so I am assuming this is a shortcode callback. Shortcodes can be hijacked. Try:

function my_first_shortcode($atts) {
  return 'howdy';
}
add_shortcode('hijack','my_first_shortcode');
echo do_shortcode('[hijack]');

function my_second_shortcode($atts) {
  return 'hijacked !';
}
add_shortcode('hijack','my_second_shortcode');
echo do_shortcode('[hijack]');

If you can find the original shortcode slug, you can put your function (probably with a different name) in your theme’s functions.php or another plugin and hijack the orginal shortcode.

function my_HSA_shortcode( $atts ) {
  // ...
}
do_shortcode('origslug','my_HSA_shortcode');

This, of course, will work only until the plugin author changes the shortcode “slug”, but even then the maintenance hassle is greatly reduced.

Leave a Comment