Put WordPress’ 4.4 oEmbed JS in your site footer

1 min read
Watb Team
A person working on code

With WordPress 4.4 came a raft of improvements, including a new oEmbed feature. In their own words:

“Starting with version 4.4, WordPress becomes an oEmbed provider as well, allowing any oEmbed consumer to embed posts from WordPress sites….”

“…this new feature means that any post (or basically any public post type) will now be embeddable. If you’re using pretty permalinks, the embeddable content will be available at example.com/your-post/embed/.

For most WordPress users this is great, and it’s not a feature we want to remove. You can if you insist by using this plugin.

However, if like us, your main concern was more JS in your site’s header, you can use these actions to move the code that this feature inserts into your site’s footer instead:

// Remove oEmbed discovery links from header and place in footer
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
add_action( 'wp_footer', 'wp_oembed_add_discovery_links' );

// Remove oEmbed-specific JavaScript from the front-end and back-end header and place in footer
remove_action( 'wp_head', 'wp_oembed_add_host_js' );
add_action( 'wp_footer', 'wp_oembed_add_host_js' );

We haven’t tested whether this maintains the functionality however, so use at your own risk.

Related Posts

Posts you may also like