Title: kill multiple youtube players
Last modified: November 23, 2019

---

# kill multiple youtube players

 *  [jjon](https://wordpress.org/support/users/jjon/)
 * (@jjon)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/kill-multiple-youtube-players/)
 * Very tyro, rookie with php and wordpress. I wanted a sort of category page that
   the twentyseventeen theme didn’t offer, and I didn’t find a straightforward plugin
   that would give me what I want, so, learning as I go, I thought I’d hack on it
   myself.
 * Starting with the twentyseventeen archive.php template as a base, I’ve been building
   a tentative custom category page (at the linked address). It displays a lot of
   video posts. It is possible now to set more than one of these videos going at
   once, and the bandwidth will not effectively support simultaneous streams. Is
   there any php I could embed in my template that would kill all other video players
   when a video is ‘played’?
 * Failing that, does anybody know a DOM event I might hijack in javascript that
   would serve this purpose?
    -  This topic was modified 6 years, 5 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
      Reason: Moved to Fixing WordPress, this is not a Developing with WordPress
      topic
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fkill-multiple-youtube-players%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/kill-multiple-youtube-players/#post-12166373)
 * PHP?? No. You’re making a classic rookie mistake of thinking PHP can manage anything
   on a page after it has been output. It can’t because it runs on the server. The
   page now resides in the browser. Only JavaScript or its many variants like jQuery
   can run on a browser. (Well, there are extensions for other languages, but you
   cannot expect users to have them installed)
 * It’s actually impossible to access the YT play button and disable it with JS 
   because the button lies within an externally sourced iframe. Being able to access
   it is seen as cross-site scripting, which is blocked for security reasons.
 * Just having many embedded YT players on a page really drags down page load speeds
   even if they are not playing. One scheme you could implement is to merely have
   static images representing embedded players. When any one is clicked, your script
   puts up a modal that contains the actual player clicked, having been dynamically
   loaded by the click event on the static image. Any click outside the player kills
   the modal and the embed it contained. Thus users can only play one vid at a time.
 * If you ask me, it’s not worth doing anything to protect user’s bandwidth. It’s
   not like these all auto-play. If someone starts multiple streams, it’s their 
   own fault that they took up all available bandwidth.
 *  Thread Starter [jjon](https://wordpress.org/support/users/jjon/)
 * (@jjon)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/kill-multiple-youtube-players/#post-12167737)
 * Thanks [@bcworkz](https://wordpress.org/support/users/bcworkz/), that was quite
   helpful. Rookie mistake, yes. I can remember making the same mistake when I first
   built something in PHP decades ago.
 * >  It’s actually impossible to access the YT play button and disable it with 
   > JS because the button lies within an externally sourced iframe. Being able 
   > to access it is seen as cross-site scripting, which is blocked for security
   > reasons.
 * In a different context, and without all this PHP, I embeded a vimeo player in
   a page and found it had an easily accessible API so that I could do this:
 *     ```
       <script>
         function unloadVimeo(player) {
           var p = new Vimeo.Player(document.getElementById(player));
           p.unload();
         }
       </script>
       ```
   
 * where `player` is the ID of a dom element. YouTube has no similar API?
 * I like your static images with modal player idea, but I’m trying to keep the 
   extra code to a minimum
 * As to user’s bandwidth; yeah, you’re right.
 * j

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘kill multiple youtube players’ is closed to new replies.

## Tags

 * [categories](https://wordpress.org/support/topic-tag/categories/)
 * [video](https://wordpress.org/support/topic-tag/video/)
 * [Youtube](https://wordpress.org/support/topic-tag/youtube/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [jjon](https://wordpress.org/support/users/jjon/)
 * Last activity: [6 years, 5 months ago](https://wordpress.org/support/topic/kill-multiple-youtube-players/#post-12167737)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
