I am using a media field to allow people to paste in youtube urls like: hidden link
Then I use [types field='sermon-video-url'][/types] to show the videos, which it does nicely on the frontend of website. But, ever since I added this line into my functions.php file:
add_filter('embed_oembed_html', 'soundCloud_mini_embed', 10, 3);
It stops youtube embeds from showing anymore. Now nothing shows where the video should be showing. I edited the embed for soundcloud, so that's why that line even exists in my functions.php file. I need to keep it in there. So how do I get the youtube video to show too? I don't see how one should affect other.
Thanks!
Hello,
The PHP codes you mentioned above, will add a filter into filter hook "embed_oembed_html" with PHP function "soundCloud_mini_embed", see WordPress document:
https://developer.wordpress.org/reference/functions/add_filter/#parameters
$function_to_add
(callable) (Required) The callback to be run when the filter is applied.
there might some problem in that PHP function "soundCloud_mini_embed", how do you setup the PHP function "soundCloud_mini_embed"?
With other plugin/theme? please provide detail steps to duplicate the same problem, thanks
The whole function is this. Does that help? As soon as I remove the add_filter('embed_oembed_html', 'soundCloud_mini_embed', 10, 3); line, youtube embeds work again.
function soundCloud_mini_embed($html, $url) {
// Only use this filter on Soundcloud embeds
if(preg_match("/soundcloud.com/", $url)) {
// array of patterns to find in the oembed iframe html
$patterns = array();
$patterns[0] = "/visual=true/"; // true means a big image background
$patterns[1] = "/show_artwork=true/"; // true means show the track artwork
$patterns[2] = "/ height=\"\d+?\"/"; // height of standard embed is in the 400-pixel range. Just look for any height integer
$patterns[3] = "/ width=\"\d+?\"/"; // width of standard embed in WordPress seems to be a fixed pixel width. Look for any integer
// array of replacements to make for these patterns
$replacements = array();
$replacements[0] = "visual=false"; // turn off big image background
$replacements[1] = "show_artwork=false"; // turn off track artwork
$replacements[2] = " height=\"166\""; // set iframe height to 166 pixels, the embed standard for the Soundcloud mini player
$replacements[3] = " width=\"100%\""; // set iframe to full width instead of fixed pixel dimension
// prophylactic ksort to make sure that all patterns and replacments will line up regardless of what order they're input
ksort($patterns);
ksort($replacements);
// one function to do all the find and replace
$html = preg_replace($patterns, $replacements, $html);
// return the html string and save to database or output
return $html;
}
}
// hook into the WordPress oembed filter
add_filter('embed_oembed_html', 'soundCloud_mini_embed', 10, 3);
Basically I have to do all this because I want the smaller mini soundcloud template and not the square one oembed does by default.
There is a bug in the PHP codes you mentioned above, please try to change these lines from:
// return the html string and save to database or output
return $html;
}
To:
// return the html string and save to database or output
}
return $html;
And test again
Thanks! Worked perfectly!