• Resolved colevalleygirl

    (@colevalleygirl)


    My users create content using the Classic Editor and are used to linking to a video by entering the YouTube URL, which WordPress turns into an embedded video.

    I would like these videos to open in FancyBox when clicked, but can’t achieve this. I have FancyBox enabled for YouTube , but AutoDetection doesn’t seem to be happening.

    I have tried with all other plugins disabled and the theme set to Twenty-Twenty.

    Is this something that ought to work?

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @colevalleygirl the light box needs a link to open. It will not work on an embedded video. I’m not sure if it was possible with the Classic Editor to paste a URL and make it a link instead of letting it be converted to an embedded video.

    In the new editor this is fairly easy: after pasting the URL on a new line, it will convert to an embedded video block but you can change the block to a paragraph block with a linked URL. In the old editor it might not be so easy.

    A possible work-around to prevent the embedded video from appearing: First type some text (or even a space) and then paste the URL on the same line not a new paragraph! Or better: type the title of the video, then select the title and click the “Insert/edit link” icon. Then paste the URL there to make it a link.

    The link itself will be detected by Easy FancyBox and will open in a light box.

    Thread Starter colevalleygirl

    (@colevalleygirl)

    Thanks. I’ll need to find a way to make it simpler for my users… and to retrofit it to existing video content.

    Retrofitting will be difficult. You’d either need to disable the automatic embedding done by WordPress, at least for youtube URLs, or replace it with your own.

    Info on how to disable auto-embeds can be found on https://kinsta.com/knowledgebase/disable-embeds-wordpress/ for example.

    But then, the inserted URLs might still not be a link, just a URL as plain text. In this case, you’d actually need to reactivate WordPress auto-embedding and replace tit by a conversion from a URL to a link.

    To do that, you could use the embed_oembed_html filter hook, like this:

    add_filter( 'embed_oembed_html', 'convert_youtube_url_to_link', 10, 2 );
    function convert_youtube_url_to_link( $html, $url ) {
    	if ( strpos( $url, 'https://www.youtube.com/watch?v=' ) !== false && strpos( $url, 'https://youtu.be/' ) !== false) {
    		$html = '<a href="' . $url '" target="_blank" class="fancybox-youtube">View video</a>';
    	}
    
    	return $html;
    }
    Thread Starter colevalleygirl

    (@colevalleygirl)

    Thanks; that’s helpful. I need to go and have a good long think ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Fancybox for Youtube embedded videos’ is closed to new replies.