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!
Hi! Thanks gor the snippet. Where should I exactly paste it to get LYTE working again after upgrading Elementor to 3.1?
The easiest & safest solution is using the code snippets plugin 🙂
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.
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.
Yes I can add that plugin, is there any chance you can provide any code to add in snippet ?
I was assuming you wanted to add the code snippet in above blog post? What is it you want to do exactly?