子テーマでスタイルシートを読み込み【TCD019】

wordpress

functions.php、style.css、style_pc.css、style_sp.cssを子テーマ用フォルダに用意

functions.phpを作成

[php] <?php add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_styles’ ); function theme_enqueue_styles() { wp_enqueue_style( ‘parent-style’, get_template_directory_uri() . ‘/style.css’ ); } ?> [/php]
style.css
[css] /* Theme Name:子テーマのディレクトリ名 Template:親テーマのディレクトリ名 */ [/css]
style_pc.css
[css] @import url(‘../precious_tcd019/style_pc.css’); [/css]
style_sp.css
[css] @import url(‘../precious_tcd019/style_sp.css’); [/css]

style_pc.cssとstyle_sp.cssは親テーマをインポート

header.phpの

[php] <link rel="stylesheet" href="<?php bloginfo(‘template_url’); ?>/style.css<?php version_num(); ?>" type="text/css" /> <link rel="stylesheet" media="screen and (min-width:641px)" href="<?php bloginfo(‘template_url’); ?>/style_pc.css<?php version_num(); ?>" type="text/css" /> <link rel="stylesheet" media="screen and (max-width:640px)" href="<?php bloginfo(‘template_url’); ?>/style_sp.css<?php version_num(); ?>" type="text/css" /> [/php]

上記を下記へ変更

[php] <link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/style.css<?php version_num(); ?>" type="text/css" /> <link rel="stylesheet" media="screen and (min-width:641px)" href="<?php echo get_stylesheet_directory_uri(); ?>/style_pc.css<?php version_num(); ?>" type="text/css" /> <link rel="stylesheet" media="screen and (max-width:640px)" href="<?php echo get_stylesheet_directory_uri(); ?>/style_sp.css<?php version_num(); ?>" type="text/css" /> [/php]