Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuadavidnelson/dc2990036db16f9e7584239bb7002498 to your computer and use it in GitHub Desktop.
Save joshuadavidnelson/dc2990036db16f9e7584239bb7002498 to your computer and use it in GitHub Desktop.
Place jQuery in the head on archive pages. You can use other conditionals in place of `is_archive()` to achieve this behavior for other conditions.
<?php
/**
* Use this filter to force jquery to remain in the head section of the page on archives.
*
* @see https://wordpress.org/support/topic/exclude-jquery-for-other-archive-pages/
* @date 2021-07-02
*/
add_filter( 'stf_jquery_header', 'jdn_archive_header_scripts', 10 );
function jdn_archive_header_scripts( $bool ) {
if ( is_archive() ) { // conditional check for the current page, is it an archive?
return true;
}
return $bool;
}
// Alternative, if you have a archive.php template, you could also use the built-in `__return_true`
// function to filter from within the setting from within the archive.php template file:
add_filter( 'stf_jquery_header', '__return_true' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment