twenty twelveのデフォルトテーマからcssとjsをfunction.phpに記載される様になりました。
なぜこの様になったかというと子テーマを作成する際に@importで親テーマのcssを読み込む必要がなくfunction.phpで読み込むことができるようになり何かと便利らしいです。
twenty twelveでのcss、jsは「twentytwelve_scripts_styles」って関数で読み込みされてます。
↓こんな感じ
/**
* Enqueues scripts and styles for front-end.
*
* @since Twenty Twelve 1.0
*/
function twentytwelve_scripts_styles() {
global $wp_styles;
/*
* Adds JavaScript to pages with the comment form to support
* sites with threaded comments (when in use).
*/
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
wp_enqueue_script( 'comment-reply' );
/*
* Adds JavaScript for handling the navigation menu hide-and-show behavior.
*/
wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '1.0', true );
/*
* Loads our special font CSS file.
*
* The use of Open Sans by default is localized. For languages that use
* characters not supported by the font, the font can be disabled.
*
* To disable in a child theme, use wp_dequeue_style()
* function mytheme_dequeue_fonts() {
* wp_dequeue_style( 'twentytwelve-fonts' );
* }
* add_action( 'wp_enqueue_scripts', 'mytheme_dequeue_fonts', 11 );
*/
/* translators: If there are characters in your language that are not supported
by Open Sans, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'twentytwelve' ) ) {
$subsets = 'latin,latin-ext';
/* translators: To add an additional Open Sans character subset specific to your language, translate
this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language. */
$subset = _x( 'no-subset', 'Open Sans font: add new subset (greek, cyrillic, vietnamese)', 'twentytwelve' );
if ( 'cyrillic' == $subset )
$subsets .= ',cyrillic,cyrillic-ext';
elseif ( 'greek' == $subset )
$subsets .= ',greek,greek-ext';
elseif ( 'vietnamese' == $subset )
$subsets .= ',vietnamese';
$protocol = is_ssl() ? 'https' : 'http';
$query_args = array(
'family' => 'Open+Sans:400italic,700italic,400,700',
'subset' => $subsets,
);
wp_enqueue_style( 'twentytwelve-fonts', add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" ), array(), null );
}
/*
* Loads our main stylesheet.
*/
wp_enqueue_style( 'twentytwelve-style', get_stylesheet_uri() );
/*
* Loads the Internet Explorer specific stylesheet.
*/
wp_enqueue_style( 'twentytwelve-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentytwelve-style' ), '20121010' );
$wp_styles->add_data( 'twentytwelve-ie', 'conditional', 'lt IE 9' );
}
add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' );
うーん難しい・・・(笑)どうやらcssもjsも同様の関数で読み込まれてるみたいですね。
もっと簡単にかつcssとjsを別々に書いてみる
正直ちょっとわかりづらかったので自作テーマを制作する際に、function.phpで、cssとjsを別関数に分けて読み込ませるようにしてみました。
css読み込み関数【set_styles】
//スタイルシート読み込み
function set_styles(){
wp_enqueue_style('theme-style',get_stylesheet_uri());
}
add_action('wp_enqueue_scripts','set_styles');
js読み込み関数【set_scripts】
//スクリプト読み込み
function set_scripts(){
if(is_singular() && comments_open() && get_option('thread_comments')){
wp_enqueue_script('comment-reply');
}
if(!is_admin()){
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js');
wp_enqueue_script('jquery');
wp_enqueue_script('googlemaps','http://maps.google.com/maps/api/js?sensor=false',array('jquery'),NULL);
}
}
add_action('wp_enqueue_scripts','set_scripts');
両関数とも「wp_enqueue_scripts」のアクションフックで処理されるので分ける必要は全くないんですけど、とりあえずわかりやすく分けておいた方が後々のメンテナンスが楽になるかなって思いこんな感じに毎回カスタムしてます。
あ、もちろん【wp_head】と【wp_footer】の記述は忘れないようにしましょう。