LoginSignup
1
2

More than 5 years have passed since last update.

WordPressでのパス記述に関するちょっとしたメモ

Posted at

WordPressを使っていて、はじめに躓いたのがパスの記述。
ルート相対パスなるものを知ったのだけれど、テスト環境だと使えなかったりもする。

結局、一番使ってるのは

bloginfo('template_url');

だったりする。

テンプレートタグ/bloginfo からの引用

'template_url' / 'template_directory' - アクティブなテーマのディレクトリー URL を表示します。
('template_directory' は Version 2.6 以前ではローカルパスを表示していました。ハック的な代替策は
get_theme_root() と get_template() を参照してください)。 子テーマの中では、 get_bloginfo('template_url') と
get_template() はどちらも親テーマのディレクトリーを返します。そのため、親テーマでは
get_template_directory_uri() を、子テーマでは get_stylesheet_directory_uri() を使うよう考慮してください。

他にも

// プライマリーな CSS (usually style.css) ファイルの URL
bloginfo('stylesheet_url');  
get_stylesheet_uri();

// アクティブなテーマディレクトリーの URL
bloginfo('stylesheet_directory');  
get_stylesheet_directory_uri();

なんかがあるようだ。
使い分けについては今後の課題。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2