Ticket #6518 (closed enhancement: fixed)
Shortcode escaping
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 2.8 |
| Component: | General | Version: | 2.5 |
| Severity: | normal | Keywords: | has-patch |
| Cc: |
Description
In 2.5.0 there's no official syntax for escaping a shortcode. This makes it difficult to write a post that gives examples of shortcode usage:
Here's how to use the [gallery] tag...
It's possible to work around it by using HTML entities to represent the square brackets but that's ugly.
The enclosed patch improves the shortcode parser to support an escaping syntax:
Here's how to use the [[gallery]] tag...
The output looks like this, with the extra brackets removed:
Here's how to use the [gallery] tag...
It only affects valid shortcode tags, so [[not-a-tag]] displays the input unmodified.
I have unit tested it for common cases including invalid escaping syntax with unbalanced brackets (test_tag_escaped() and test_tag_not_escaped()):
http://svn.automattic.com/wordpress-tests/wp-testcase/test_shortcode.php
Attachments
Change History
comment:1
tellyworth — 4 years ago
nb, double-escaping works too: [[[gallery]]] outputs [[gallery]].
the Markdown escape syntax is also worth looking into:
[gallery] -> not escaped
[gallery] -> escaped
[gallery] -> also escaped
D.
and wiki formatting needs better escaping as well ;-)
[gallery] -> not escaped `[gallery]` -> escaped `` [gallery] `` -> also escaped
comment:5
follow-up:
↓ 6
stringfold — 4 years ago
I agree that this is a problem that needs fixing. (Was a real pain for me until I found a workaround). I would favor the shortcode? format and not those tick marks (unless WP starts using them elsewhere).
I wrote a workaround for my plugin (AZIndex). I simply added another parameter to my shortcode escape="true" for when I wanted to display the shortcode unmodified (in plugin documentation, for example).
But it would be nice to see this fixed in the next release.
comment:6
in reply to:
↑ 5
stringfold — 4 years ago
Replying to stringfold:
I agree that this is a problem that needs fixing. (Was a real pain for me until I found a workaround). I would favor the shortcode ? format and not those tick marks (unless WP starts using them elsewhere).
I wrote a workaround for my plugin (AZIndex). I simply added another parameter to my shortcode escape="true" for when I wanted to display the shortcode unmodified (in plugin documentation, for example).
But it would be nice to see this fixed in the next release.
Oops -- ? is the escape format I favor.
- Owner changed from ryan to westi
- Status changed from new to assigned
- Milestone changed from 2.9 to 2.8
comment:10
westi — 3 years ago
- Status changed from assigned to closed
- Resolution set to fixed

