Title: Change iframe src on refresh?
Last modified: August 20, 2016

---

# Change iframe src on refresh?

 *  [jimmytuesday](https://wordpress.org/support/users/jimmytuesday/)
 * (@jimmytuesday)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/change-iframe-src-on-refresh/)
 * I have an embedded Vimeo video on my homepage (In the index.php template file)
   and I am using their embed code which makes use of iframes. (I target the iframe
   in my video menu underneath, so that works well for what I’m doing.)
 * I’d like that video area, the iframe, to display one of three different videos(
   randomly chosen) when you load the page. When you refresh the page a different
   video, presumably, would load.
 * I think what I need is some Javascript that, for this one little section of my
   site, will choose between 3 different code snippets (3 different vimeo embeds)
   every time the page loads, but I’m a bit of newbie at Javascript and at a loss
   of how to do this.
 * Does anyone have any suggestions? Am I barking up the wrong tree?
 * Thank you for any help!

Viewing 1 replies (of 1 total)

 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/change-iframe-src-on-refresh/#post-3548083)
 * Seeing as how you’re doing this in a template, I wouldn’t use JavaScript. You’re
   better off using PHP to be able to do this.
 *     ```
       $urls = array (
         "http://site.com/video1.mp4",
         "http://site.com/video2.mp4",
         "http://site.com/video3.mp4"
       );
   
       $rand = mt_rand (0, count ($urls) - 1);
   
       echo "<iframe src='".$urls [$rand]."'></iframe>";
       ```
   
 * What you’re doing there is setting u the video URL’s, then generating a random
   number between 0 and 2 (in PHP all array indexs start at 0, not 1 so for an array
   with three items you choose between 0 and 2, not 1 and 3). From there you output
   the value at that index. That will give you a random video URL each time, and
   all you need to do to add in another video URL is to add a new line in the $url
   array.

Viewing 1 replies (of 1 total)

The topic ‘Change iframe src on refresh?’ is closed to new replies.

## Tags

 * [Alternate](https://wordpress.org/support/topic-tag/alternate/)
 * [different](https://wordpress.org/support/topic-tag/different/)
 * [embed](https://wordpress.org/support/topic-tag/embed/)
 * [iframe](https://wordpress.org/support/topic-tag/iframe/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [load](https://wordpress.org/support/topic-tag/load/)
 * [video](https://wordpress.org/support/topic-tag/video/)
 * [vimeo](https://wordpress.org/support/topic-tag/vimeo/)

 * 1 reply
 * 2 participants
 * Last reply from: [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/change-iframe-src-on-refresh/#post-3548083)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
