Last active
October 6, 2015 07:28
-
-
Save ounziw/2958103 to your computer and use it in GitHub Desktop.
テンプレート階層に応じたスタイルシートを出力する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
WordPress テーマの functions.php に追加して使用する。
詳細は下記参照
http://ounziw.com/2012/06/12/css-hierarchy/