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

wordpress

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

functions.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' ); 
} ?>
style.css
/*
Theme Name:子テーマのディレクトリ名
Template:親テーマのディレクトリ名
*/
style_pc.css
@import url('../precious_tcd019/style_pc.css');
style_sp.css
@import url('../precious_tcd019/style_sp.css');

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

header.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" />

上記を下記へ変更

<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" />