当サイト、Codex 日本語版は今後積極的な更新は行わない予定です。後継となる新ユーザーマニュアルは、https://ja.wordpress.org/support/ にあります。
万が一、当サイトで重大な問題を発見した際などは、フォーラムWordSlack #docs チャンネルでお知らせください。</p>

関数リファレンス/get theme root

提供: WordPress Codex 日本語版
< 関数リファレンス
2015年5月18日 (月) 09:17時点におけるMiccweb (トーク | 投稿記録)による版 (関連項目)

(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索

テーマディレクトリの絶対パスを取得します。この時、最後のスラッシュは記載されません。

使用法

<?php get_theme_root(); ?>

パラメーター

$stylesheet_or_template
string) (必須) テーマのスタイルシートまたはテンプレート名
初期値: なし

戻り値

(string) 
テーマディレクトリの絶対パス。ただし、最後のスラッシュは記載されません。

使用例

テーマディレクトリ内のサブディレクトリ数

テーマディレクトリ内のサブディレクトリ数を引用する関数です。これは WordPress が認識していると一致している必要はありません。

<?php
function display_themes_subdirs_count_info()
  $theme_root = get_theme_root();
  $files_array = glob("$theme_root/*", GLOB_ONLYDIR);
  echo . $theme_root " ディレクトリには"  . count($files_array) . "個のサブディレクトリがあります。";
}
?>

出力例:

/home/user/public_html/wp-content/themes ディレクトリには 5 個のサブディレクトリがあります。

改訂履歴

1.5.0 にて導入されました。

ソースファイル

get_theme_root()wp-includes/theme.php にあります。

テーマのパス: get_template(), get_template_directory(), get_template_directory_uri(), get_theme_roots() /en, get_theme_root(), get_theme_root_uri() /en, get_stylesheet() /en, get_stylesheet_uri(), get_stylesheet_directory(), get_stylesheet_directory_uri(), get_bloginfo()



最新英語版: WordPress Codex » Function Reference/get theme root 最新版との差分


関数リファレンステンプレートタグ目次もご覧ください。