Skip to content

Instantly share code, notes, and snippets.

@Langmans
Last active May 29, 2019 07:02
Show Gist options
  • Save Langmans/1660ae1176a83d5689a6c8fdbeae7930 to your computer and use it in GitHub Desktop.
Save Langmans/1660ae1176a83d5689a6c8fdbeae7930 to your computer and use it in GitHub Desktop.
turn off jquery, autoptimize and supercache for specific user agent
<?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 );
}
<?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 );
}
} );
<?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