Add_shortcode not working (and how to fix it)

If you wonder why your shortcode does not work as expected in WordPress (or does not work at all), it might be because it has not been registered correctly.

Shortcodes need to be registered at the init level. Otherwise WordPress does not receive them correctly, and consequently does not execute them appropriately.

The code below worked for me. Likely you will need to change gallery in something else.

remove_shortcode(‘gallery’, ‘gallery_shortcode’);  
add_action(‘init’, ‘add_my_gallery_shortcode’, 99);  
function add_my_gallery_shortcode() {  
  add_shortcode( ‘gallery’, ‘my_gallery_shortcode’);  
function my_gallery_shortcode( $attr ) {  
  // the new gallery logic here  

The 99 is the priority. Higher the priority, later the instruction will be executed, which will eventually allow your shortcode to override default behaviors.

Hopefully this will help.

Further resources