Created
January 29, 2015 15:55
-
-
Save Ikaring/3ae2df65724c904d592f to your computer and use it in GitHub Desktop.
enqueue script template
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 | |
/** | |
* JavascriptとCSSの設定 | |
*/ | |
function my_scripts() { | |
global $post; | |
// テーマ全体で必要なJavascriptとCSS | |
wp_enqueue_style( 'theme-style', get_stylesheet_uri() ); | |
wp_enqueue_script( 'theme-script', get_template_directory_uri() . '/js/script.js', array( 'jquery' ), '', false ); | |
//トップページに必要なJavascript | |
if ( is_front_page() ){ | |
wp_enqueue_script( 'my-front-script', get_template_directory_uri() . '/js/jquery.front.js', array( 'jquery' ), '', false ); | |
} | |
} | |
add_action( 'wp_enqueue_scripts', 'my_scripts' ); | |
/** | |
* IE9以下の設定 | |
*/ | |
function my_enqueue_lt_ie9() { | |
global $is_IE; | |
// IEでない時はおしまい | |
if ( ! $is_IE ) return; | |
// 必要ならファイルをインクルード | |
if ( ! function_exists( 'wp_check_browser_version' ) ) | |
include_once( ABSPATH . 'wp-admin/includes/dashboard.php' ); | |
// IEバージョンによってenqueue | |
$response = wp_check_browser_version(); | |
if ( 0 > version_compare( intval( $response['version'] ) , 9 ) ){ | |
wp_enqueue_script( 'my-html5', '//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.2/html5shiv.js', array(), '', false ); | |
} | |
} | |
add_action( 'wp_enqueue_scripts', 'my_enqueue_lt_ie9' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment