Comma separated YouTube playlist shortcode not working

Hi! I want to create a shortcode for YouTube playlists that also works for single tracks.

Here’s what a three track playlist looks like:

<iframe src="https://www.youtube-nocookie.com/embed/?playlist=dQw4w9WgXcQ,J6scECNOYvY,HX2Oz2xkRzc" style="aspect-ratio:16/9;border:0;width:100%" loading="lazy" allowfullscreen></iframe>

Just supplying one YouTube ID works too, for a single video. Like so:

<iframe src="https://www.youtube-nocookie.com/embed/?playlist=dQw4w9WgXcQ" style="aspect-ratio:16/9;border:0;width:100%" loading="lazy" allowfullscreen></iframe>

So I created layouts/shortcodes/youtube.html containing:

<iframe src="https://www.youtube-nocookie.com/embed/?playlist={{ index .Params 0 }}" style="aspect-ratio:16/9;border:0;width:100%" loading="lazy" allowfullscreen></iframe>

and tried this in a blog post:

{{< youtube dQw4w9WgXcQ,J6scECNOYvY,HX2Oz2xkRzc >}}

But, the comma separated formatting does not seem to be working. I get this error message:

unrecognized character in shortcode action: U+002C ','

It’d be nice if it did work somehow, because then I could use the same shortcode for both single YouTube videos and playlists.

Like so:
{{< youtube dQw4w9WgXcQ >}} for single
{{< youtube dQw4w9WgXcQ,J6scECNOYvY,HX2Oz2xkRzc >}} for playlist

Clues? Do I have to escape the commas some way?

Wrap with quotes.

1 Like

Awesome, thanks!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.