[wp-hackers] wordpress shortcodes
Haluk Karamete
halukkaramete at gmail.com
Mon Feb 3 22:59:42 UTC 2014
I have a shortcode like this;
[shortcode
_arg1="val1"
_arg1="val2"]
[/shortcode The way it stands, it does not work.
I know that if I were to remove the carriage returns in between the
attributes, it would work.
but hey, that's not news...
The problem is that I'd like to keep those carriage returns in the post
editor for visually clarify purposes.
I did some tests on built-in shortcodes.
It turns out that [caption] shortcode tolerates any number of empty lines
in between the
args. But audio shortcode on the other hand suffers from carriage returns.
you can copy this section from this email and paste it into a new post and
see it for yourself.
<begin_copy>
caption shortcode example. this works with any number of carriage returns.
It's rock solid.
[caption
id="attachment_9"
align="alignleft"
width="500"]<img src="
http://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Great_Wave_off_Kanagawa2.jpg/300px-Great_Wave_off_Kanagawa2.jpg"
alt="Kanagawa" title="The Great Wave" width="300" height="205"
class="size-medium wp-image-6" /> The Great Wave
[/caption]
<hr>
audio shortcode example. this one works in a limited fashion. It works with
one carriage return but fails if there are more than one:
working example of the audio shortcode with no carriage return :
[audio mp3="
http://www.schillmania.com/projects/soundmanager2/demo/_mp3/rain.mp3"
][/audio]
<hr>
working example of the audio shortcode with 1 carriage return :
[audio
mp3="http://www.schillmania.com/projects/soundmanager2/demo/_mp3/rain.mp3"
][/audio]
<hr>
Not working example. The following audio shortcode would not work. It does
not like that extra line in its definition. Therefore, you won't be able to
see third audio player.
[audio
mp3="http://www.schillmania.com/projects/soundmanager2/demo/_mp3/rain.mp3"
][/audio]
The fact that you do not see that 3rd audio player here puzzles me.. The
question is why is it that extra line causes a problem in the audio
shortcode but that's not an issue in the caption shortcode?
I tried this with many other shortcodes. It looks like none is as robust as
the caption shortcode. Most suffers from carriage returns.
Below also works;
[caption
id="attachment_6"
align="alignright"
width="200"]
<img src="
http://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Great_Wave_off_Kanagawa2.jpg/300px-Great_Wave_off_Kanagawa2.jpg"
alt="Kanagawa" title="The Great Wave" width="300" height="205"
class="size-medium wp-image-6" /> The Great Wave
[/caption]
</end_copy>
My question is two parts.
How can I remove those carriage returns (on the fly) before the WordPress's
shortcode parser kicks in?
And what makes the caption shortcode so robust?
More information about the wp-hackers
mailing list