Discussion:
Image caption shortcode format change
Jeff Tchang
2013-12-16 22:09:48 UTC
Permalink
I was recently implementing a python shortcode parser and adding support
for [caption] shortcodes.

I ran into a snafu in trying to determine if the caption shortcode format
had an attribute called "caption" as one of the parameters.

It turns out before this commit on May 2012 it did:

http://core.trac.wordpress.org/changeset/20679

This changeset removed the caption attribute. Around line 155 is what I am
talking about:


$shcode = '[caption id="' . $id . '" align="align' . $align
. '" width="' . $width . '" caption="' . $caption . '"]' . $html .
'[/caption]';

$shcode = '[caption id="' . $id . '" align="align' . $align . '"
width="' . $width . '"]' . $html . ' ' . $caption . '[/caption]';

Was there a reason to remove the caption attribute? The shortcode becomes a
lot harder to parse dynamically.

-Jeff
Otto
2013-12-16 22:24:15 UTC
Permalink
Post by Jeff Tchang
Was there a reason to remove the caption attribute?
People wanted to put HTML into their captions. Number one request for
captions, by far.

And <a href="whatever">Linked caption</a> becomes extremely difficult to do
when you have them in an attribute and thus have to fiddle with quotes in
the caption breaking the quotes around the attribute.

-Otto
Jeff Tchang
2013-12-17 01:45:44 UTC
Permalink
Post by Otto
Post by Jeff Tchang
Was there a reason to remove the caption attribute?
People wanted to put HTML into their captions. Number one request for
captions, by far.
And <a href="whatever">Linked caption</a> becomes extremely difficult to do
when you have them in an attribute and thus have to fiddle with quotes in
the caption breaking the quotes around the attribute.
How about sticking a wp-caption class around the caption and wrapping it in
a span tag?


<span class="wp-caption">$caption</span>

This way you can actually parse it if needed.
Andrew Ozz
2013-12-17 04:15:45 UTC
Permalink
Post by Jeff Tchang
How about sticking a wp-caption class around the caption and wrapping it in
a span tag?
Not really needed as the $html in

`[caption ...]' . $html . ' ' . $caption . '[/caption]`

is either an <img> or an <a><img></a> which can be extracted relatively
easy. Here's the JS regex that does it in the editor:
http://core.trac.wordpress.org/browser/trunk/src/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin_src.js#L143
Jeff Tchang
2013-12-17 05:04:45 UTC
Permalink
Post by Andrew Ozz
Post by Jeff Tchang
How about sticking a wp-caption class around the caption and wrapping it in
a span tag?
Not really needed as the $html in
`[caption ...]' . $html . ' ' . $caption . '[/caption]`
is either an <img> or an <a><img></a> which can be extracted relatively
http://core.trac.wordpress.org/browser/trunk/src/wp-
includes/js/tinymce/plugins/wpeditimage/editor_plugin_src.js#L143
Gotcha. I do find the regex rather difficult to understand though. Also it
seems cleaner to give it a class so people can target it via jquery and css.
Loading...