-
-
Save hazephase/a76429f0021e5400a7177270da8738cc to your computer and use it in GitHub Desktop.
Twenty Seventeen Theme - Better Version Control
This file contains hidden or 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 | |
/** | |
* Asset Loaders and Helpers for Twenty Seventeen Theme | |
* | |
* @since 1.0.0 | |
* @author hellofromTonya | |
* @link https://KnowTheCode.io | |
* @license GNU-2.0+ | |
*/ | |
add_action( 'wp_enqueue_scripts', 'twentyseventeen_scripts' ); | |
/** | |
* Enqueue scripts and styles. | |
*/ | |
function twentyseventeen_scripts() { | |
$version_number = get_theme_version(); | |
// Add custom fonts, used in the main stylesheet. | |
wp_enqueue_style( 'twentyseventeen-fonts', twentyseventeen_fonts_url(), array(), null ); | |
// Theme stylesheet. | |
wp_enqueue_style( 'twentyseventeen-style', get_stylesheet_uri(), array(), $version_number ); | |
// Load the dark colorscheme. | |
if ( 'dark' === get_theme_mod( 'colorscheme', 'light' ) || is_customize_preview() ) { | |
wp_enqueue_style( 'twentyseventeen-colors-dark', get_theme_file_uri( '/assets/css/colors-dark.css' ), array( 'twentyseventeen-style' ), $version_number ); | |
} | |
// Load the Internet Explorer 9 specific stylesheet, to fix display issues in the Customizer. | |
if ( is_customize_preview() ) { | |
wp_enqueue_style( 'twentyseventeen-ie9', get_theme_file_uri( '/assets/css/ie9.css' ), array( 'twentyseventeen-style' ), $version_number ); | |
wp_style_add_data( 'twentyseventeen-ie9', 'conditional', 'IE 9' ); | |
} | |
// Load the Internet Explorer 8 specific stylesheet. | |
wp_enqueue_style( 'twentyseventeen-ie8', get_theme_file_uri( '/assets/css/ie8.css' ), array( 'twentyseventeen-style' ), '1.0' ); | |
wp_style_add_data( 'twentyseventeen-ie8', 'conditional', 'lt IE 9' ); | |
// Load the html5 shiv. | |
wp_enqueue_script( 'html5', get_theme_file_uri( '/assets/js/html5.js' ), array(), '3.7.3' ); | |
wp_script_add_data( 'html5', 'conditional', 'lt IE 9' ); | |
wp_enqueue_script( 'twentyseventeen-skip-link-focus-fix', get_theme_file_uri( '/assets/js/skip-link-focus-fix.js' ), array(), '1.0', true ); | |
$twentyseventeen_l10n = array( | |
'quote' => twentyseventeen_get_svg( array( 'icon' => 'quote-right' ) ), | |
); | |
if ( has_nav_menu( 'top' ) ) { | |
wp_enqueue_script( 'twentyseventeen-navigation', get_theme_file_uri( '/assets/js/navigation.js' ), array( 'jquery' ), '1.0', true ); | |
$twentyseventeen_l10n['expand'] = __( 'Expand child menu', 'twentyseventeen' ); | |
$twentyseventeen_l10n['collapse'] = __( 'Collapse child menu', 'twentyseventeen' ); | |
$twentyseventeen_l10n['icon'] = twentyseventeen_get_svg( array( 'icon' => 'angle-down', 'fallback' => true ) ); | |
} | |
wp_enqueue_script( 'twentyseventeen-global', get_theme_file_uri( '/assets/js/global.js' ), array( 'jquery' ), '1.0', true ); | |
wp_enqueue_script( 'jquery-scrollto', get_theme_file_uri( '/assets/js/jquery.scrollTo.js' ), array( 'jquery' ), '2.1.2', true ); | |
wp_localize_script( 'twentyseventeen-skip-link-focus-fix', 'twentyseventeenScreenReaderText', $twentyseventeen_l10n ); | |
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { | |
wp_enqueue_script( 'comment-reply' ); | |
} | |
} | |
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'); | |
// if ( site_is_in_debug_mode() ) { | |
// $stylesheet = get_stylesheet_directory() . '/style.css'; | |
// | |
// return filemtime( $stylesheet ); | |
// } | |
// | |
// return '1.3'; | |
} | |
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 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment