Skip to content

Instantly share code, notes, and snippets.

@hellofromtonya
Created July 11, 2017 01:28
Show Gist options
  • Select an option

  • Save hellofromtonya/9060a5604f69694e99e35561641f2a6c to your computer and use it in GitHub Desktop.

Select an option

Save hellofromtonya/9060a5604f69694e99e35561641f2a6c to your computer and use it in GitHub Desktop.
Better Asset Versioning - Genesis Child Theme - Versioning
<?php
/**
* Assets loader and helpers
*
* @package Genesis Sample Theme
* @since 1.0.0
* @author hellofromTonya
* @link https://KnowTheCode.io
* @license GNU-2.0+
*/
//* Enqueue Scripts and Styles
add_action( 'wp_enqueue_scripts', 'genesis_sample_enqueue_scripts_styles' );
function genesis_sample_enqueue_scripts_styles() {
wp_enqueue_style( 'genesis-sample-fonts', '//fonts.googleapis.com/css?family=Source+Sans+Pro:400,600,700', array(),
CHILD_THEME_VERSION );
wp_enqueue_style( 'dashicons' );
wp_enqueue_script( 'genesis-sample-responsive-menu', get_stylesheet_directory_uri() . '/js/responsive-menu.js',
array( 'jquery' ), '1.0.0', true );
$output = array(
'mainMenu' => __( 'Menu', 'genesis-sample' ),
'subMenu' => __( 'Menu', 'genesis-sample' ),
);
wp_localize_script( 'genesis-sample-responsive-menu', 'genesisSampleL10n', $output );
}
/**
* Get the theme's version.
*
* When in development/mode mode, it uses the style.css modification time.
* Else, it grabs the version number from the stylesheet.
*
* @since 1.0.0
*
* @return string|int
*/
function get_theme_version() {
$version_number = get_asset_current_version_number( get_stylesheet_directory() . '/style.css' );
if ( $version_number !== false ) {
return $version_number;
}
$theme = wp_get_theme();
return $theme->get('Version');
}
function get_asset_current_version_number( $asset_file ) {
if ( ! site_is_in_debug_mode() ) {
return false;
}
return filemtime( $asset_file );
}
/**
* Checks if the site is in development/debug mode.
*
* @since 1.0.0
*
* @return bool
*/
function site_is_in_debug_mode() {
if ( ! defined( 'SCRIPT_DEBUG' ) ) {
return false;
}
return ( (bool) SCRIPT_DEBUG === true );
}
@hellofromtonya
Copy link
Author

hellofromtonya commented Jul 11, 2017

This gist is for the Better Asset Versioning hands-on lab on Know the Code. It's for episode 6 - Forget Hard Coding - Genesis.

Place this file into lib/support/assets-helper.php in your child theme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment