Skip to content

Instantly share code, notes, and snippets.

@ounziw
Last active October 6, 2015 07:28
Show Gist options
  • Save ounziw/2958103 to your computer and use it in GitHub Desktop.
Save ounziw/2958103 to your computer and use it in GitHub Desktop.
テンプレート階層に応じたスタイルシートを出力する
/**
* @author Fumito MIZUNO http://php-web.net/
* @license GPL ver.2 or later {@link http://www.gnu.org/copyleft/gpl.html}
*/
add_action('wp_head','page_template_css') ;
function page_template_css() {
global $template;
$dir = '/css'; // (テーマ配下の)スタイルシートを入れるディレクトリを設定する
$pos = strrpos($template, "/");
$template = substr($template, $pos);
$filename = str_replace('php', 'css', $template);
$fullfilename = get_stylesheet_directory() . $dir . $filename;
if (file_exists($fullfilename)) {
print '<link rel="stylesheet" type="text/css" href="' . get_stylesheet_directory_uri() . $dir . $filename . '" />';
print "\n";
}
}
@ounziw
Copy link
Author

ounziw commented Jun 20, 2012

WordPress テーマの functions.php に追加して使用する。

詳細は下記参照
http://ounziw.com/2012/06/12/css-hierarchy/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment