[wp-hackers] wordpress shortcodes
Otto
otto at ottodestruct.com
Tue Feb 4 02:06:09 UTC 2014
Actually, your caption code doesn't work at all for me. Inserting blank
lines causes the caption to not appear.
The extra blank lines aren't accepted inside shortcodes because the regex
being used for them doesn't like it. If you want to try to sort out why,
then you can examine the regex in the get_shortcode_regex() function.
But there is no functional difference between the caption shortcode and the
audio shortcode, because shortcode functions do not parse their own text,
generally. The core parses the shortcode including the attributes, then
calls the appropriate function to handle it. Shortcode functions never see
those blank lines, they only get an array of attributes.
-Otto
On Mon, Feb 3, 2014 at 4:59 PM, Haluk Karamete <halukkaramete at gmail.com>wrote:
> 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?
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list