in WordPress

Are We Adding add_shortcode Properly in Plugin?

WordPress one of the most popular function is add_shortcode. We can use this in theme or plugin.
The most simple way of adding a new shortcode is like

add_shortcode('my_gf_unique_name', 'callback_function');
function callback_function($atts){
  //do your duty for your gf unique name
}

But we should not use the add_shortcode in same way in plugin but call it from an ‘init’ action callback.

add_action('init', 'init_callback');
function init_callback(){
 add_shortcode('my_gf_unique_name', 'callback_function');
}

function callback_function($atts){
  //do your duty for your gf unique name
}

Reference: WordPress Developer portal plugin handbook

Everyday I am trying to learn something new. Whenever I find something new like this I try to update my old plugins and use the new learning in new plugin.

What did you learn new this week ?