• I need to block/disable all embeds on WordPress except Twitter, in both the backend and frontend.

    How to best do this?

    There is a question similar to this on Stackoverflow from nearly 4.5 years ago (https://stackoverflow.com/questions/19466374/), but unfortunately I couldn’t get the code in any of the answers to work, and I imagine WordPress core has likely changed significantly during this time.

    I see one could use wp_oembed_remove_provider() to remove individual providers, but as WordPress changes providers between updates, this seems untenable to keep them all blocked, except Twitter.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    You could use https://developer.www.ads-software.com/reference/hooks/oembed_providers/ to get a list of providers then use the function you cited to remove them all other than twitter.

    Essentially, get an array of providers, remove twitter from that array, then pass it to the remove function.

    Thread Starter Trippetchz

    (@trippetchz)

    Hi there,

    Thanks for your note.

    How do I do what you’ve suggested? There are no examples on that link.

    I’ve also got no idea where to put code either. Stackoverflow suggested functions.php but I’ve also seen people suggesting it needs to be a plugin because the oEmbed stuff is initialised before the theme…

    Thanks.

    • This reply was modified 4 years, 9 months ago by Trippetchz.
    • This reply was modified 4 years, 9 months ago by Trippetchz.
    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    I think you’ll have to experiment a bit. I’d make a simple plugin to keep it apart from themeing.

    Thread Starter Trippetchz

    (@trippetchz)

    Okay thanks, but the solution is still not clear. I’m looking for an answer with code and where to put it, as I don’t know how to do this.

    Thanks!

    Thread Starter Trippetchz

    (@trippetchz)

    PS this doesn’t work in functions.php nor as a simple plugin:

    	function filter_oembed_provider_list( $providers ) {
    		// edit the whitelist to your needs
    		// $whitelist = array( 'youtu', 'twitter' );
    		$whitelist = array( 'twitter' );
    
    		$output = array();
    
    		foreach( $providers as $key => $provider )
    		{
    			foreach( $whitelist as $allowed )
    			{
    				if( stristr( $key, $allowed ) )
    					$output[$key] = $provider;
    
    			}
    		}
    		return $output; 
    	}
    	add_filter( 'oembed_providers' , 'filter_oembed_provider_list', 999 );
    
    • This reply was modified 4 years, 9 months ago by Trippetchz.
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Disable all oembed_providers except Twitter’ is closed to new replies.