Move Selected Scripts to the Footer
Moves the scripts you list from the page head to the footer, so they stop blocking the page from rendering.
Opens WPIDE on
Code
// Script handles to print in the footer. Find handles in the page source: id="HANDLE-js".
$wpide_footer_scripts = array( 'some-slider', 'some-plugin-frontend' );
add_action( 'wp_enqueue_scripts', function () use ( $wpide_footer_scripts ) {
$scripts = wp_scripts();
foreach ( $wpide_footer_scripts as $handle ) {
if ( isset( $scripts->registered[ $handle ] ) ) {
$scripts->add_data( $handle, 'group', 1 );
}
}
}, 999 );
Notes
A script stays in the head if another head script depends on it, so test interactive features afterwards.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.