Last active
July 9, 2016 07:04
-
-
Save adyngom/889ae97f4d820abd1136c97206d12fa3 to your computer and use it in GitHub Desktop.
Properly adding conditional styles ( IE 8 , IE 9 etc...) and scripts to your wordpress theme
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 | |
/** | |
* Wordpress is @ 4.5.3 | |
* https://developer.wordpress.org/reference/functions/wp_style_add_data/ | |
* https://developer.wordpress.org/reference/functions/wp_script_add_data/ | |
* no need to use global $wp_data | |
* add to your theme's functions.php file | |
* */ | |
define('THEME_TEMPLATE_PATH', get_template_directory_uri()); | |
function theme_name_scripts () { | |
// add conditional IE 9 | |
wp_enqueue_style('theme-ie-9', THEME_TEMPLATE_PATH . '/assets/css/ie9.css'); | |
wp_style_add_data('theme-ie-9', 'conditional', 'lt IE 9'); | |
// add conditional IE 8 | |
wp_enqueue_style('theme-ie-8', THEME_TEMPLATE_PATH . '/assets/css/ie8.css'); | |
wp_style_add_data('theme-ie-8', 'conditional', 'lt IE 8'); | |
// add respond.min.js if lte IE8 | |
wp_enqueue_script('respond', THEME_TEMPLATE_PATH . '/assets/js/ie/respond.min.js'); | |
wp_script_add_data('respond', 'conditional', 'lte IE 8'); | |
} | |
add_action('wp_enqueue_scripts', 'theme_name_scripts'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment