8

I have a shortcode defined in a plugin as follows:

// [tag1] -> Some Longer Text
function shortcode_example1() {
    return 'Some Longer Text';
}
add_shortcode('tag1', 'shortcode_example1');

Now within a wordpress page I am trying to access the plugin as follows:

[tag1]

However, the shortcode is not run and the output is just "[tag1]". Can you help?

Thanks for your help.

  • Your code works for me on WP 3.9.2, either in a plugin or functions.php. Do other shortcodes work OK? – Gabriel Sep 5 '14 at 23:29
  • 1
    I also confirm that this shortcode works ok. Has something removed the do_shortcode filter from the the_content hook? Try switching to a default theme (is your theme using the_content()?) and disabling all plugins. Then enable them 1 by 1 to find the potential conflict. – helgatheviking Sep 6 '14 at 20:27
31

There are a couple of things to check here

  • One: Is your plugin activated.

  • Two: Is your shortcode in your main plugin file. If that code is in another file inside your plugin, did you make sure to include that extra file into your main plugin file

  • Three: Don't you have any type of error in your plugin file that deactivates your plugin after activation. Have you set debug to true. One of the site's members have an excellent debugging plugin available for download on wordpress.org called Debug Objects

  • Four: Try moving your shortcode to your theme's functions.php to make sure that your shortcode is actually working. If it doesn't work inside your theme, the problem might actually be in your theme itself

  • Five: As suggested by @helgatheviking, aren't you filtering the the_content() in any way that might cause this behavior

  • Six: If all of the above fails, deactivate all plugins, switch to a bundled theme, and recheck. If the problem persist, upgrade/reinstall Wordpress, as this might be a corrupted core file then

  • I did the checklist: 1=check!, 2=yes!, 3=nope, 4=ok, 5=nope, 6-> worked! After switching my local wp (for testing) from 'Sydney Theme' to 'Twenty Fourteen' the SC gets shown. Seems that there are themes which prevent SCs from showing in posts. – Martin Pfeffer Mar 13 '17 at 3:02
  • Thanks Pieter for this checklist. Turns out I hadn't included my file correctly ... woops. Works fine now :) – Chess Byte May 15 '18 at 10:55
  • I did all the following and still it does not work. I have new WordPress (5.0.2) install with code added to functions.php file. But when i put [shortcodename] in a page it is treated as text. What is wrong? I use default theme: Twenty Sixteen. – hal Jan 4 at 13:08
  • This is a super helpful checklist. The only thing I'd add would be a Seven: make sure your page editor isn't jacking up your shortcode like mine was: [plc_get_matter_detail_per_contact contacts=6c131-<wbr />668f13139e matters=6c620185-6211-1331-a642-668f6b7eea9e] That 'helpful' WordBreak screwed me up for a while. Thanks page editor... – Brian Stinar Nov 8 at 7:46
-2

add this

    add_filter('the_content', 'do_shortcode');
  • 1
    Why? What does this do? Where would they add this? Please edit your answer using the edit link above and add in more information on how this helps solve the problem. – Howdy_McGee Oct 22 '18 at 14:22
-5

Thanks for your responses. After further investigation, I found that the plugin file where my shortcode was defined was showing up as "inactive". Once I moved my shortcode definitions into an active file, then everything began to work. I hope this is useful for anybody who runs into this in the future.

Thanks again!

  • Please accept the correct answer instead of your own. – Chess Byte May 15 '18 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.