Snippets: Add Parameters to all Youtube Lightbox Videos

add_action( 'wp_footer', function() { ?>
	
	<script>
		( function( $ ) {
			'use strict';

			// Get lightbox elements
			var $lightboxLinks = $( '.wpex-lightbox' );

			// Loop through all lightbox elements
			$lightboxLinks.each( function() {

				var $this = $( this ),
					$href = $this.attr( 'href' );

				// Alter youtube links
				if ( $this.data( 'type' ) == 'iframe' && $href.indexOf( 'youtube' ) !== -1 ) {
					$this.attr( 'href', $href + '?modestbranding=1' ); // Add parameters here
				}

			} );
		} ) ( jQuery );
	</script>
 
<?php } );

Snippet Type: PHP

Posted Under: Lightbox

All PHP snippets should be added via a child theme's functions.php file.