1

I am trying to do a simple basic shortcode and it fails. I have boiled it down to the most simple test and it still fails.

Here is the code:

/** My test shortcode */
function bp_basic_shortcode() {
return "This is a shortcode doing this!";
}
add_shortcode( 'basic_shortcode', 'bp_basic_shortcode');

In trying to figure out what is the reason I have:

I have put this in the functions.php file of the stock template twentytwelve

I have deactivated all plugins

I have added the shortcode [basic-shortcode] in both a post and a page as a test with the same result.

I used the "text" tab of the editor to add the shortcode

I see just the text of [basic-shortcode] but it is not being processed.

I even installed a plugin to show all active shortcodes and it is indeed in the list.

I have tried it both on an instance of my MAMP server and one on my VPS

This should be really simple. What am I missing??

2 Answers 2

4

You registered the shortcode basic_shortcode, but you tested the wrong [basic-shortcode]. These are two different things.

3
  • Not trying to argue - honestly. I assure you I used the underscores initially in the [basic_shorcode] tag I placed in the page under the text tab. When I changed them in the action declaration and the page to "-" the shortcake worked both locally and on the server.
    – jmcbade
    Commented Aug 15, 2017 at 7:40
  • @toscho codex.wordpress.org/Shortcode_API#Hyphens doesn't say anything about "invalid", it just points out some side effect risks. I've been using hyphenized shortcodes without any issues for years.
    – lkraav
    Commented Aug 20, 2017 at 15:05
  • 1
    @lkraav True, I remember some problems, but it doesn't look like an issue anymore. Updated my answer. :)
    – fuxia
    Commented Aug 20, 2017 at 17:01
-2

Silly spell check on the MAC - It's "shortcodes" not "shortcakes"

But to answer the question - this is SO trivial stupid and I had not seen this mentioned anywhere: You MAY NOT use an underscore in the shortcode tag.

Maybe this will help someone else. I sure hope so.

3
  • That's not true. Underscores are fine, hyphens are not.
    – fuxia
    Commented Aug 14, 2017 at 7:09
  • I thought they should be but in WP 4.8.1 they fail as tested in my MAMP and online server. I changed them to "-"s and all is well. Crazy huh? Maybe a bug introduced in this version?
    – jmcbade
    Commented Aug 15, 2017 at 7:35
  • @toscho Can you confirm if this is true in 4.8.1 or not in your own testing?
    – jmcbade
    Commented Aug 16, 2017 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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