• Resolved DickRaney

    (@dickraney)


    We have a function that automatically turns off related videos when we embed via WordPress. Here is the function

    function remove_related_videos($html, $url, $attr) {
    	if ( strpos ( $html, 'feature=oembed' ) !== false ) { 
    	   	return str_replace( 'feature=oembed', 'feature=oembed&rel=0', $html ); 
    	} else { 
    	   	return $html; 
    	}
    }
    add_filter( 'embed_oembed_html', 'remove_related_videos', 10, 3);

    It doesn’t work with LazyLoad. When you pause a video or reach the end it displays a list of related videos. Is there a way to make our function work with LazyLoad or some other way to prevent related videos?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author WP Media

    (@wp_media)

    Which options of our plugin do you have active?

    Do you have an example page with the issue, for which we could have a look at the source code?

    Thread Starter DickRaney

    (@dickraney)

    Here’s a sample page

    We have all 3 options checked: Images, Iframes & Videos, and Replace Youtube videos by thumbnail

    Plugin Author WP Media

    (@wp_media)

    function remove_related_videos($html, $url, $attr) {
    	if ( strpos ( $html, 'feature=oembed' ) !== false ) { 
    	   	return str_replace( 'feature=oembed', esc_attr( 'feature=oembed&rel=0' ), $html ); 
    	} else { 
    	   	return $html; 
    	}
    }
    add_filter( 'embed_oembed_html', 'remove_related_videos', 10, 3);

    This works correctly. Note the use of esc_attr() around the new value to make it compatible with URL parsing

    Thread Starter DickRaney

    (@dickraney)

    Awesome!!! Works like a charm.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Remove related videos’ is closed to new replies.