当サイト、Codex 日本語版は今後積極的な更新は行わない予定です。後継となる新ユーザーマニュアルは、https://ja.wordpress.org/support/ にあります。
万が一、当サイトで重大な問題を発見した際などは、フォーラムや WordSlack #docs チャンネルでお知らせください。</p>
万が一、当サイトで重大な問題を発見した際などは、フォーラムや WordSlack #docs チャンネルでお知らせください。</p>
関数リファレンス/get theme root
提供: WordPress Codex 日本語版
テーマディレクトリの絶対パスを取得します。この時、最後のスラッシュは記載されません。
使用法
<?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 個のサブディレクトリがあります。
注
- 引用されたパスに theme_root フィルターを適用させるために、 apply_filters() を用います。
改訂履歴
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 (最新版との差分)
関数リファレンス、テンプレートタグ目次もご覧ください。