Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save senooat/f05e3f915d3029a7510d355437afdc45 to your computer and use it in GitHub Desktop.
Save senooat/f05e3f915d3029a7510d355437afdc45 to your computer and use it in GitHub Desktop.
wp_head()やwp_footer()にCSSやJSを読み込む方法
//サイトURLを定数に設定
define('SITEURL', home_url());
//jQueryを指定のものに変更(falseだとwp_head()に読み込む)
wp_deregister_script('jquery');
wp_enqueue_script('jquery', SITEURL.'/js/library/jquery.min.js',array(), '', false);
//JSの読み込み(trueだとwp_footer()に読み込む)
wp_enqueue_script('tempjs-script', SITEURL.'/js/script.js',array(), '', true);
//IE 9未満(IE8以下)のみでJSを読み込ませる
wp_enqueue_script('tempjs-selectivizr', ROOTURL.'/js/library/selectivizr.js',array(), '', true);
wp_script_add_data('tempjs-selectivizr', 'conditional', 'lt IE 9');
//style.cssを読み込み
wp_enqueue_style( 'tempcss-style', get_stylesheet_uri() );
//その他CSSの読み込み
wp_enqueue_style( 'tempcss-common', SITEURL. '/css/common.css',array(), '', 'all');
//その他CSSカテゴリー別に読み込みたい場合(例,投稿タイプ「staffblog」とカテゴリ「news」)
if( is_front_page() && !is_paged() ):
//ここに処理を記述
elseif( is_category() || is_single() || is_archive() ):
if(is_post_type_archive('staffblog') || is_singular('staffblog') || is_tax('staffblog_cat') ):
wp_enqueue_style( 'tempcss-staffblog', SITEURL. '/css/staffblog.css',array(), '', 'all');
else:
if(is_category('news') || in_category('news') ):
wp_enqueue_style( 'tempcss-news', SITEURL. '/css/news.css',array(), '', 'all');
endif;
endif;
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment