Fix for Elementor 3.1 YouTube not LYTE anymore

Elementor 3.1 came with “refactored YouTube source to use YouTube API in Video widget” which resulted in WP YouTube Lyte not being able to lyten up the YouTubes any more. Below code snippet (consider it beta) hooks into Elementor to fix this regression;

add_filter( 'elementor/frontend/widget/should_render', function( $should_render, $elementor_element ) {
	if ( function_exists( 'lyte_preparse' ) && 'Elementor\Widget_Video' === get_class( $elementor_element ) ) {
		$pas = get_private_property( $elementor_element , 'parsed_active_settings');
		if ( ! empty( $pas['youtube_url'] ) ) {
			echo lyte_preparse( $pas['youtube_url'] );
			return false;
		}
	}

	return $should_render;
}, 10, 2 );

// from https://www.lambda-out-loud.com/posts/accessing-private-properties-php/
function get_private_property( object $object, string $property ) {
    $array = (array) $object;
    $propertyLength = strlen( $property );
    foreach ( $array as $key => $value ) {
        if ( substr( $key, -$propertyLength ) === $property ) {
            return $value;
        }
    }
}

Hat tip to Koen for his assistance in digging into Elementor, much appreciated!

6 thoughts on “Fix for Elementor 3.1 YouTube not LYTE anymore

  1. Kasia

    Hi! Thanks gor the snippet. Where should I exactly paste it to get LYTE working again after upgrading Elementor to 3.1?

    Reply
  2. Ashish Agrawal

    Hi Frank,
    Can you please provide a snippet for rank math as well. Its a cool plugin for inserting snippets however wp youtube lyte is not working on its snippets. \

    Thanks in advance boss
    You’re a life saver.

    Reply
    1. frank Post author

      As far as I know the snippets in Rank Math are not for PHP-code Ashish, you need something (e.g. code snippets) that allows you to add PHP code.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.