Last active
August 29, 2015 14:21
-
-
Save obiPlabon/577d07ede6b3fc4cfdb6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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