WordPress Shortcode Not Working

WordPress Shortcode Not Working

Are your shortcode is not working? Having a problem implementing shortcodes?

Go through the article to learn more about WordPress Shortcode.

Add Heading

What is a Shortcode?

Shortcodes did introduce with the WordPress Version 2.5. You can create fantabulous functionality into your post or page with shortcodes without writing any HTML or PHP code.

Shortcode in WordPress allows you to add several functionalities not only in posts, and pages but also in widgets. You can also use the shortcode inside your WordPress text widgets. Simply drag-drop a text widget on your sidebar and add your shortcode inside it. Through shortcodes, it is possible to create mixed content in your posts, pages, and widgets. In simple words you can say, the shortcode is a shortcut.

How Does It Look?

Let’s assume that you have applied a shortcode for displaying a gallery of images. A shortcode is anything within square braces.

WordPress Shortcode Not Working

Shortcodes are very much similar to the WordPress filters, both accept the attributes and return an output.

Rules For writing Shortcode

  • Shortcode names should be all lowercase.
  • Must use letters.
  • Number and underscore are allowed.
  • Shortcode names must never contain the following characters:
1. square braces: []
2. Angle braces: <>
3. Ampersand: &
4. Forward slash: /
5. Whitespace: space, tab
6. Quotes: ', "

How to Create a shortcode?

The add_shortcode function is used to register a shortcode handler. It accepts two parameters:

1. Shortcode Name.

2. Callback Function.

add_shortcode( 'demo_shortcode', 'demo_shortcode_callback_function' );
function demo_shortcode_callback_function( $atts ){
	return "Welcome to WordPress";
}

This creates the [demo_shortcode] that will return Welcome to WordPress message.

Shortcodes in widgets and template files

As you have seen what a shortcode can do, now you probably may be wondering that how you can add a shortcode in your widgets and in your template files. To activate shortcodes in your widgets area, just put the following code in the functions.php file:

add_filter('widget_text', 'do_shortcode');

You can access a shortcode by using:

do_shortcode("[ my_shortcode ]");

Why is Shortcode not Working?

There are a couple of things you have to check if your shortcode is not working.

1. Is your plugin activated? Check whether the plugin providing the shortcode is active or not. If it is not active, then the shortcode won’t work.

2. Your theme is outputting the post content without applying the needed filters to it.

3. Is your shortcode in your main plugin file? If not, then include the file containing code into your main plugin file.

4. Have you set debug to true? Check for the error in your plugin file.

5. Move the shortcode to your theme’s functions.php file. Make sure that your shortcode is actually working or not.

6. Is all of the above fails, deactivate all plugins and recheck. If the problem persists, reinstall WordPress, as this might be a corrupted core file then.

Scroll to Top