Add_shortcode not working in WordPress – How to Fix

Add shortcode in WordPress not working so you need to take 2 step or may be 3 step. Checkout how to tackle shortcode problem in WordPress.

Shortcode is a tremendous achievement of WordPress to solve hundred of problems. The Add_shortcode not working and broken content may appears. while developing a plugin or displaying content using shortcode (e.g Custom post type with Shortcode). Explore add_shortcode not working or crash below some huge findings to solve your wp short code problem.

Fix Add_Shortcode not Working – WordPress

Shortcode problem can be solved via overriding, registering at init level,

  • Shortcode may already exists in a theme. Remove it first then add it again.
  • Shortcode needs to be registered at init level.
  • Overrides previously registered short code.

Remove_Shortcode to Override Shortcode:

Theme developer already register the code, remove it by remove_shortcode.

remove_shortcode('your_shortcode_name');

add_shortcode('your_shortcode_name','function');

Try Adding Shortcode at Init Level:

use add_action with init to add the code.

function abc(){
 add_shortcode('shortcode_name','function');
 }

add_action('init','abc');

Final Fix: Override all behavior of ShortCode:

May be you’re adding shortcode (e.g. gallery) already registered by core developers. follow the steps to tackle it. We are taking the example of Gallery shortcode.

Example of Code:

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 number 99 is the priority for action to execute.  Higher priority executes in the end and overlap previous functionalities. Setting priority makes more possibility to overcome shortcode failure.


Add Shortcode & Add Action:

Leave a Reply

Your email address will not be published. Required fields are marked *