Last active
May 29, 2019 07:02
-
-
Save Langmans/1660ae1176a83d5689a6c8fdbeae7930 to your computer and use it in GitHub Desktop.
turn off jquery, autoptimize and supercache for specific user agent
This file contains 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 | |
// at the top of wp-config.php | |
if ( isset( $_SERVER, $_SERVER['HTTP_USER_AGENT'] ) | |
&& false !== stripos( $_SERVER['HTTP_USER_AGENT'], 'some-ua' ) | |
) { | |
define( 'DISABLE_SUPERCACHE', true ); | |
define( 'DONOTMINIFY', true ); | |
define( 'NO_JQUERY', true ); | |
} else { | |
define( 'NO_JQUERY', false ); | |
} |
This file contains 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 | |
// put this anywhere in functions.php of your theme | |
add_action( 'wp_enqueue_scripts', function () { | |
if ( ! is_admin() ) { | |
if ( NO_JQUERY ) { | |
$combined_file = '/assets/js/combined_nojquery.js'; | |
} else { | |
$combined_file = '/assets/js/combined.js'; | |
} | |
wp_enqueue_script( 'combined-js', get_template_directory_uri() . $combined_file, [], | |
date( 'YmdHis', filemtime( get_template_directory() . $combined_file ) ), true ); | |
} | |
} ); |
This file contains 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 | |
// put this at the bottom of wp-content/wp-cache-config.php | |
if ( DISABLE_SUPERCACHE ) { | |
$cache_enabled = false; | |
$super_cache_enabled = false; | |
} else { | |
$cache_path = __DIR__ . '/cache/'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment