Ampersand in WordPress Shortcode

I made a shortcode for wordpress and the code from functions.php looks like this:

return '<div class="video-shortcode"><iframe width="600" height="365" src="/watch.php?file=' . $atts['file'] . '&img=' . $atts['img'] . '" frameborder="0" scrolling="no" allowfullscreen></iframe></div>';

When i’m using it, the source code from the post should look like this:

Read More
<iframe width="600" height="365" src="/watch.php?file=myfile.mp4&img=myimg.jpg" frameborder="0" scrolling="no" allowfullscreen></iframe>

But for some reason, the ampersand before the ‘img’ appears as this:

&

Related posts

Leave a Reply

2 comments

  1. I was having a similar issue. There is very little to do that won’t be breaking basic WordPress functions. To break basic WP functions see this answer. For the “right” answer see this answer. I’m using the latter successfully.

    Basically use &amp; not the other html entity, as this is considered correct XML and is parsed in the iFrame tag by browsers.