Hello again,
Apologies on the delayed response. I’m just getting out of the vacation backlog now.
The issue here turns out to be that conditional tags (like is_page()
) don’t work in that filter due to where it occurs within the plugin.
I’ve issued an update and as of version 0.6.3 of the plugin you can use conditional tags correctly in this filter. Once you update, the following code will work.
I couldn’t tell from your post if you were trying to “Keep jQuery in the Header” globally and push it into the footer for a specific page, OR if you were keeping it in the footer globally (the setting for “Keep in header” _not_ checked) and trying to place it in the header on a specific page.
So, here are both options:
/**
* If the global option 'Keep jQuery in Footer' is NOT checked, this will
* keep jquery in the header on the specific page.
*/
add_filter( 'stf_exclude_scripts', 'jdn_keep_jquery_in_header_scripts', 10, 1 );
function jdn_keep_jquery_in_header_scripts( $scripts ) {
if( is_page( 2 ) )
$scripts[] = 'jquery'; // The script handle is used here
return $scripts;
}
/**
* If the global option 'Keep jQuery in Footer' is checked, this will
* keep jquery in the footer on the specific page.
*/
add_filter( "stf_exclude_scripts", "jdn_keep_jquery_in_footer", 10, 1 );
function jdn_keep_jquery_in_footer( $scripts ) {
// Checks the page, confirms we have a valid array, and checks for 'jquery' in the array
// Then pulls the 'jquery' value out of the array
if( is_page( 2 ) && is_array( $scripts ) && in_array( 'jquery', $scripts ) ) {
$scripts = array_diff( $scripts, array( 'jquery' ) );
}
return $scripts;
}