Title: Shortcode For Playlist
Last modified: May 2, 2017

---

# Shortcode For Playlist

 *  Resolved [leoly](https://wordpress.org/support/users/leoly/)
 * (@leoly)
 * [9 years ago](https://wordpress.org/support/topic/shortcode-for-playlist-2/)
 * Hello,
    We have the following shortcode for a Playlist – `[lyte id="PLID" audio
   =”true” playlist=”true” /]`
 * We would like for the playlist to start from a random number – which was achieved
   by doing the following and adding to a PHP page template –
    `<iframe src="https://
   www.youtube.com/embed?listType=playlist&list=PLID&index=<?php print(rand(1,200))?
   >" width="560" height="315" frameborder="0"></iframe>`
 * We can get the shortcode to work from the template via –
    `<?php echo do_shortcode('[
   lyte id="PLID" audio=”true” playlist=”true” /]'); ?>`
 * Is there a way to add the &index into the shortcode, so that the playlist can
   start from a random number? The iframe does what we need, but we like the audio-
   only feature of the plugin. So if there is a way to style the iframe to look 
   like the audio-only styling, that would help as well. Thanks.

Viewing 15 replies - 1 through 15 (of 18 total)

1 [2](https://wordpress.org/support/topic/shortcode-for-playlist-2/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/shortcode-for-playlist-2/page/2/?output_format=md)

 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [9 years ago](https://wordpress.org/support/topic/shortcode-for-playlist-2/#post-9087539)
 * you can try `<?php echo do_shortcode('[lyte id="PLID&index='.print(rand(1,200)).'"
   audio=”true” playlist=”true” /]'); ?>`, i’ve seen others having some success 
   with this non-official approach (although I think it was for individual video’s,
   not playlists). no guarantees though 🙂
 * frank
 *  Thread Starter [leoly](https://wordpress.org/support/users/leoly/)
 * (@leoly)
 * [9 years ago](https://wordpress.org/support/topic/shortcode-for-playlist-2/#post-9090223)
 * Thank you for the prompt response. Unfortunately, it keeps printing out this 
   error –
 * `148" audio=”true” playlist=”true” /][lyte id="PLID&index=1`
 * Where the 148 above is a number that changes with each refresh, so it is printing
   out a random number, but putting it in the wrong place, and thus breaking the
   code.
 * Is it possible to make the changes in a similar method has mentioned in these
   topics – [https://wordpress.org/support/topic/individual-playlist-not-working/](https://wordpress.org/support/topic/individual-playlist-not-working/)
   
   [https://wordpress.org/support/topic/problems-with-playlists-in-custom-fields/](https://wordpress.org/support/topic/problems-with-playlists-in-custom-fields/)
 * Or is there a way to add a filter to YouTube iframes for mobile, in a similar
   method has mentioned here –
 *     ```
       add_filter('lyte_do_mobile','lyte_on_mobile',10,0);
       function lyte_on_mobile(){
           return true;
       }
       ```
   
 * Really appreciate the assistance, thanks
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [9 years ago](https://wordpress.org/support/topic/shortcode-for-playlist-2/#post-9091448)
 * and `<?php echo do_shortcode('[lyte id="PLID&index='.rand(1,200).'" audio=”true”
   playlist=”true” /]'); ?>` ?
 *  Thread Starter [leoly](https://wordpress.org/support/users/leoly/)
 * (@leoly)
 * [9 years ago](https://wordpress.org/support/topic/shortcode-for-playlist-2/#post-9091566)
 * The shortcode isn’t broken, but the print out on the page – strips out the index
   info, so the html looks like the below (?index doesn’t show, just goes back to&
   autoplay, like with the regular shortcode).
 * `<iframe id="iF_PLID" src="https://www.youtube.com/embed/videoseries?list=PLID&
   autoplay=1&controls=1&wmode=opaque&rel=0&egm=0&iv_load_policy=3&hd=0&autohide
   =0" style="position:relative;top:-400px;" allowfullscreen="" frameborder="0" 
   height="438" width="840"></iframe>`
 * Is there a way to add it to the js file that adds the other YouTube parameters,
   i.e. controls, wmode, etc. Basically, a way to generate a random number, within
   the js script.
 * Thanks again for the assistance.
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [9 years ago](https://wordpress.org/support/topic/shortcode-for-playlist-2/#post-9091694)
 * that looks like the HTML after clicking play, what’s the HTML before having clicked
   play?
 *  Thread Starter [leoly](https://wordpress.org/support/users/leoly/)
 * (@leoly)
 * [9 years ago](https://wordpress.org/support/topic/shortcode-for-playlist-2/#post-9092250)
 * This is the html before clicking play with &index=’.rand(1,200).’
 * `<div class="lyte lyte-audio playlist lP" id="WYL_PLID"><div id="lyte_PLID" data-
   src="" class="pL"><div class="tC"><div class="tT">Playlist:Mix</div></div><div
   class="play"></div><div class="ctrl"><div class="Lctrl"></div><div class="Rctrl"
   ></div></div></div><noscript><a href="http://youtube.com/playlist?list=PLID">
   <br />Watch this playlist on YouTube</a></noscript></div>`
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [9 years ago](https://wordpress.org/support/topic/shortcode-for-playlist-2/#post-9093503)
 * ok, think I’ve got it;
 *     ```
       add_filter('lyte_match_postparse_template','playlist_randomizer');
       function playlist_randomizer($in) {
         return str_replace('class="lyMe playlist"','class="lyMe playlist qsa_\&index\='.rand(1,200).'"',$in);
       }
       ```
   
 * enjoy 🙂
 *  Thread Starter [leoly](https://wordpress.org/support/users/leoly/)
 * (@leoly)
 * [9 years ago](https://wordpress.org/support/topic/shortcode-for-playlist-2/#post-9094851)
 * Huge thanks for trying to help figure this out. Added the above code to functions.
   php and then tried out the shortcode in two ways:
 * added to a page template – `<?php echo do_shortcode('[lyte id="PLID" audio=”true”
   playlist=”true” /]'); ?>`
 * added to a page – `[lyte id="PLID" audio=”true” playlist=”true” /]`
 * and in both cases the index information was stripped out of the final html, just
   like before.
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [9 years ago](https://wordpress.org/support/topic/shortcode-for-playlist-2/#post-9094866)
 * hmm, can you try with a normal youtube playlist link in a post instead? that’s
   how I tested.
 *  Thread Starter [leoly](https://wordpress.org/support/users/leoly/)
 * (@leoly)
 * [9 years ago](https://wordpress.org/support/topic/shortcode-for-playlist-2/#post-9094943)
 * Apologies, you were right, it does work. We were getting an error, because of
   the audio only part. So: [lyte id=”PLID” audio=”true” playlist=”true” /] doesn’t
   work, the index info is stripped out, but [lyte id=”PLID” playlist=”true” /] 
   works.
 * Hurray 😀 Would appreciate if you can help with the styling to just show the 
   audio only. Thanks and left a review as well.
    -  This reply was modified 9 years ago by [leoly](https://wordpress.org/support/users/leoly/).
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [9 years ago](https://wordpress.org/support/topic/shortcode-for-playlist-2/#post-9095786)
 * indeed, we need to add the lyte-audio to the list of classes to make it work;
 *     ```
       add_filter('lyte_match_postparse_template','playlist_randomizer');
       function playlist_randomizer($in) {
         return str_replace('class="lyMe lyte-audio playlist"','class="lyMe lyte-audio playlist qsa_\&index\='.rand(1,200).'"',$in);
       }
       ```
   
 * thanks for the kind review 🙂
 * frank
 *  Thread Starter [leoly](https://wordpress.org/support/users/leoly/)
 * (@leoly)
 * [9 years ago](https://wordpress.org/support/topic/shortcode-for-playlist-2/#post-9095976)
 * Works well, thanks again 🙂
 * Just for the future, is there a way to create an array so that the randomizer
   works for both the lyMe playlist and lyMe lyte-audio playlist at the same time.
    -  This reply was modified 9 years ago by [leoly](https://wordpress.org/support/users/leoly/).
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [9 years ago](https://wordpress.org/support/topic/shortcode-for-playlist-2/#post-9096153)
 * an array would not work, as the replace-argument of str_replace would not have
   the correct classes any more. so either go regex (but let’s not) or try e.g.
 *     ```
       add_filter('lyte_match_postparse_template','playlist_randomizer');
       function playlist_randomizer($in) {
         return str_replace('class="lyMe ','class="lyMe qsa_\&index\='.rand(1,200),$in);
       }
       ```
   
 *  Thread Starter [leoly](https://wordpress.org/support/users/leoly/)
 * (@leoly)
 * [9 years ago](https://wordpress.org/support/topic/shortcode-for-playlist-2/#post-9098533)
 * Unfortunately, that didn’t work. But we have taken too much of your time already.
   Thanks again for the continued follow up 👍. Below where the html print outs 
   for the audio only shortcode and the full video.
 *     ```
       <div class="lyte qsa_\&index\=166lyte-audio playlist lP" id="PLID">
       <iframe id="iF_PLID" src="https://www.youtube.com/embed/videoseries?list=PLID&autoplay=1&controls=1&wmode=opaque&rel=0&egm=0&iv_load_policy=3&hd=0&index=166lyte-audio playlist&autohide=0" style="position:relative;top:-400px;" allowfullscreen="" frameborder="0" height="438" width="1060"></iframe></div>
       ```
   
 *     ```
       <div class="lyte qsa_\&index\=163playlist lP" id="PLID">
       <iframe id="iF_PLID" src="https://www.youtube.com/embed/videoseries?list=PLID&autoplay=1&controls=1&wmode=opaque&rel=0&egm=0&iv_load_policy=3&hd=0&index=163playlist" style="" allowfullscreen="" frameborder="0" height="298" width="1060"></iframe></div>
       ```
   
 *  Thread Starter [leoly](https://wordpress.org/support/users/leoly/)
 * (@leoly)
 * [9 years ago](https://wordpress.org/support/topic/shortcode-for-playlist-2/#post-9098580)
 * Also tried this
 *     ```
       add_filter('lyte_match_postparse_template','playlist_randomizer');
       function playlist_randomizer($in) {
         return str_replace('class="lyMe ','class="lyMe qsa_\&index\='.rand(1,200).'"',$in);
       }
       ```
   
 * and got this, which killed the playlist, because it printed out as embed/PLID,
   instead of embed/videoseries?list=PLID
 *     ```
       <div class="lyte qsa_\&index\=41 lP" lyte-audio="" playlist"="" id="PLID"><iframe id="PLID" src="https://www.youtube.com/embed/PLID?autoplay=1&controls=1&wmode=opaque&rel=0&egm=0&iv_load_policy=3&hd=0&index=41" style="" allowfullscreen="" frameborder="0" height="38" width="1060"></iframe></div>
   
       <div class="lyte qsa_\&index\=186 lP" playlist"="" id="PLID"><iframe id="PLID" src="https://www.youtube.com/embed/PLID?autoplay=1&controls=1&wmode=opaque&rel=0&egm=0&iv_load_policy=3&hd=0&index=186" style="" allowfullscreen="" frameborder="0" height="298" width="1060"></iframe></div>
       ```
   

Viewing 15 replies - 1 through 15 (of 18 total)

1 [2](https://wordpress.org/support/topic/shortcode-for-playlist-2/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/shortcode-for-playlist-2/page/2/?output_format=md)

The topic ‘Shortcode For Playlist’ is closed to new replies.

 * ![](https://ps.w.org/wp-youtube-lyte/assets/icon-128x128.png?rev=1836005)
 * [WP YouTube Lyte](https://wordpress.org/plugins/wp-youtube-lyte/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-youtube-lyte/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-youtube-lyte/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-youtube-lyte/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-youtube-lyte/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-youtube-lyte/reviews/)

 * 18 replies
 * 2 participants
 * Last reply from: [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * Last activity: [9 years ago](https://wordpress.org/support/topic/shortcode-for-playlist-2/page/2/#post-9102911)
 * Status: resolved