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?

  • How are you outputting it in the header? – Tom J Nowell Dec 5 '18 at 19:59
  • Sorry I meant the <header> – Burgi Dec 5 '18 at 22:23
  • It's still not clear how it gets on the page, your question contains a filter, but nowhere is there code that actually displays the oembed, so it's not clear how you're doing that, other than that it isn't being done via a call to the_content(), please update your question with that code – Tom J Nowell Dec 6 '18 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.