Make WordPress Core

Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#11948 closed defect (bug) (invalid)

Shortcode parser doesn't support hyphen in shortcode name

Reported by: ukdmbfan's profile ukdmbfan Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.9.1
Component: Shortcodes Keywords: reporter-feedback
Focuses: Cc:


I tried creating a Shortcode with a hyphen (-) in the name, namely "contact-us", but the parser was not recognising the Shortcode. Removing the hyphen from the name made it work.

It may be that the parser is not supposed to support hyphens in Shortcode names, however the documentation suggests that it does by using examples with hyphens in them ("my-shortcode", for example).

You should be able to easily reproduce this by creating a Shortcode with a hyphen in the name. Code I was using is below, removing the hyphen from the Shortcode name in the first parameter of the add_shortcode hook (and subsequently in the associated call in the blog post) returned the correct result. When the hyphen was present, the Shortcode tag was parsed and removed from the post, but was not replaced with the correct output and the associated function itself wasn't called at all.

Using WPMU

function contact_us_func($atts, $content = null) {
    return '123';


add_shortcode('contact-us', 'contact_us_func');
// [contact-us]


add_shortcode('contactus', 'contact_us_func');
// [contactus]

Change History (7)

#1 @scribu
14 years ago

  • Component changed from General to Shortcodes
  • Keywords needs-patch added; shortcode api wpmu removed
  • Milestone changed from Unassigned to Future Release

#2 @greenshady
14 years ago

Works for me on regular WordPress. I don't have an MU install set up to test if it's different there.

#3 @TobiasBg
14 years ago

  • Keywords hypen dash removed
  • Priority changed from low to normal
  • Severity changed from minor to normal

I use a shortcode with a hyphen in my plugin and it works just fine.

The only thing that breaks it, if I register a shortcode that is just the part until the hyphen before registering the hyphened shortcode.

In my plugin:
add_shortcode( 'table-info', ...)
add_shortcode( 'table', ...)
works fine, while
add_shortcode( 'table', ...)
add_shortcode( 'table-info', ...)
does not (well I admit I haven't tested again with WP 2.9 which has a new regex, if I remember correctly.

So, could you check that in your case you (nor any other plugin) is registering a shortcode [contact /]?

#4 @wpmuguru
14 years ago

This worked for me in MU 2.9.1:

function ra_shortcode_test( $atts, $content = null ) {
        return 'hello world';
add_shortcode( 'ra-test-code', 'ra_shortcode_test' );

#5 @sivel
14 years ago

  • Keywords reporter-feedback added; needs-patch removed

#6 @wpmuguru
13 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Since my post above, I have created several shortcodes and used hyphens in them all.

#7 @scribu
13 years ago

  • Milestone Future Release deleted
Note: See TracTickets for help on using tickets.