Skip to content

Instantly share code, notes, and snippets.

@jhayiwg
Last active October 20, 2017 03:25
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 jhayiwg/92bae4330aeb738a98022d7ab63ce9b1 to your computer and use it in GitHub Desktop.
Save jhayiwg/92bae4330aeb738a98022d7ab63ce9b1 to your computer and use it in GitHub Desktop.
Development Mode ( Ignore Caching in Dev mode )
<?php
/ *
* Development Mode ( Ignore Caching for Dev mode )
*
* This snippet generate version for all theme css and js to load the actual code when you are in development mode
* Instruction
* *Add this to your active theme functions.php
* * Add define( 'WP_ENV', 'local' ); to your wp-config.php
* * from your production server make sure you remove the defined WP_ENV or set the value to 'production'
*/
add_filter( 'script_loader_src', 'wpe_style_script_loader_src', 9999 );
add_filter( 'style_loader_src', 'wpe_style_script_loader_src', 9999 );
function wpe_style_script_loader_src( $src ) {
if( ! defined( "WP_ENV" ) || ( defined( "WP_ENV" ) && WP_ENV == 'production' ) ) return $src;
if( strpos ( $src, get_stylesheet_directory_uri() ) !== false )
$src = add_query_arg('ver', time(), $src);
return $src;
}
add_action( 'login_enqueue_scripts', 'wpe_login_stylesheet' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment