The simplest way to disable the embeds is by using a WordPress plugin like “Disable Embeds”. However, if you prefer not to use a plugin, you can add the following code to your theme’s functions.php file or a custom functionality plugin
// Disable the oEmbed REST API route
remove_action( 'rest_api_init', 'wp_oembed_register_route' );
// Turn off oEmbed auto discovery.
add_filter( 'embed_oembed_discover', '__return_false' );
// Don't filter oEmbed results.
remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );
// Remove oEmbed-specific JavaScript from the front-end and back-end.
remove_action( 'wp_head', 'wp_oembed_add_host_js' );
add_filter( 'tiny_mce_plugins', 'disable_embed_tinymce_plugin' );
// Remove all embed discovery links.
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
// Remove the JavaScript used to embed the media.
remove_action( 'wp_head', 'wp_oembed_add_host_js' );
function disable_embed_tinymce_plugin( $plugins ) {
return array_diff( $plugins, array( 'wpembed' ) );
}
The above code will also take care of removing the <link rel="alternate" ... /> tags from your site’s header.
I suggest, instead of editing your main theme’s functions.php, consider using a child theme or a custom functionality plugin to add the above code. This will ensure that you don’t lose these changes when the theme gets updated.
Good luck