1

I have been trying to get a new shortcode working and have simplified my code to almost nothing but still keep getting output of just [shortcode_name]. I must be missing something pretty fundamental but cannot work it out.

<?php
/** Bridge Card Table Display Short Code
  * Plugin Name: Bridge Card Table Shortcodes
  * Description: Short codes for rendering bridge hands and tables.
  * Version:     0.0.04
  * License:     GBP v2 or later
  * License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/

  
function cards_table($attributes){

  $args=shortcode_atts(array(
    // default values
    'title' => 'A',
    'dlr' => 'B',
    'vul' => 'C',
    'north' => 'D',
    'south' => 'E',
    'east' => 'F',
    'west' => 'G'
  ), $attributes);


  $output = "Test output: title=" . $args['title'];

  return $output;

}

// register shortcode

add_shortcode('Card Table','cards_table');

?>

I have tried stripping out all the argument code too. I have activated it (checked and double checked). Commercial and built-in short codes work perfectly.

Help please!

Thanks,

Mike

2
  • 1
    Your shortcode name has a space in it. [Card Table] is not a valid shortcode. It's probably being interpreted as a shortcode named Card with an attribute named Table. You need to name it something like card_table. Commented Aug 23, 2022 at 3:16
  • 2
    Admittedly the no-spaces, no-capitals rule isn't mentioned in the add_shortcode() documentation or the Plugin Handbook, but if you have debugging features enabled (always a good move in a development environment!) you should be receiving an error regarding an invalid tag name
    – bosco
    Commented Aug 23, 2022 at 3:22

1 Answer 1

0

As discussed in the comments, 'Card Table' is an invalid shortcode tag name.

Shortcode tag names must not contain any of the following:

  • The characters <, >, &, /, [, ], =
  • Whitespace characters (spaces, linefeeds, tabs, etc.)
  • Any other non-printing/Unicode "control code" characters

The old Codex page also recommends avoiding hyphens/dashes and uppercase letters, but there doesn't seem to be codified protections against using these characters as there are for the cases above. It's not clear to me if these recommendations are antiquated in modern releases - but it's certainly safest to avoid them without further confirmation.

While neither the add_shortcode() documentation nor the Shortcode section of the Plugin Handbook explicitly mention these restrictions, if you have debugging features enabled, shortcodes registered with a tag name which contains any of the characters outlined in the bullet points above will produce an error message to the effect of

Invalid shortcode name: Card Table. Do not use spaces or reserved characters: & / < > [ ] =

The safest option in this case may be card_table.

1
  • Problem solved - thank you very much. I knew I'd missed something but couldn't see the wood for the trees! (sorry, new here so I can't uptick yet) Mike
    – Mike
    Commented Aug 24, 2022 at 10:43

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.