Skip to content

Instantly share code, notes, and snippets.

@obiPlabon
Last active August 29, 2015 14:21
Show Gist options
  • Save obiPlabon/577d07ede6b3fc4cfdb6 to your computer and use it in GitHub Desktop.
Save obiPlabon/577d07ede6b3fc4cfdb6 to your computer and use it in GitHub Desktop.
<?php
function dequeue_scripts_on_condition() {
// you can use various conditional tags
// ex. is_page(), is_page_template()
if ( ! is_page( /* page id */ ) )
wp_dequeue_script( $handle );
if ( ! is_page_template( /* page template name */ ) )
wp_dequeue_script( $handle );
}
add_action( 'wp_enqueue_scripts', 'dequeue_scripts_on_condition' );
/**
* For single handle
*/
function set_script_in_footer() {
global $wp_scripts;
$wp_scripts->add_data( $handle, 'group', 1 );
}
add_action( 'wp_enqueue_scripts', 'set_scripts_in_footer' );
/**
* For multiple handle
*/
function set_scripts_in_footer() {
global $wp_scripts;
$handles = array(
'handle-one',
'handle-two',
'handle-three'
);
foreach( $handles as $handle )
$wp_scripts->add_data( $handle, 'group', 1 );
}
add_action( 'wp_enqueue_scripts', 'set_scripts_in_footer' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment