filters - Modify oembed code conditionally

admin2025-06-05  1

My users have sprung a requirement on me that I am having some difficulty figuring out. I've tied myself up in knots trying to unravel the the logic needed.

The original spec of this website I am building called for the a video to be autoplaying on pageload as a showreel in the header section (I know, I know! They won't listen).

I added a filter to append the embed URL with the autoplay options etc.

add_filter('oembed_result', [$this,'modifyEmbedCode']);
public function modifyEmbedCode($html){
    $result=str_replace("?app_id=122963", "?app_id=122963&loop=1&background=1&autoplay=1", $html);

    return $result;
}

This works fine but now they want to still be able to embed a video in the WYSIWYG editor and have it retain the standard Vimeo controls and not to autoplay.

Is there a way to make the filter context-aware and only be applied when the_content is NOT being outputted?

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749125867a316583.html

最新回复(0)