0
0

More than 1 year has passed since last update.

【備忘録】【Wordpress】wp_enqueue_style()は特定の第一引数を渡すと予想外の挙動を引き起こす

Posted at

タイトルの通り。これで2時間ぐらい無駄にしたので書き残しておく。
テーマを読み込むとき、wp_enqueue_style()を使うが、

functions.php
wp_enqueue_style(
  'about', 
  get_theme_file_uri("/css/about.css"),
  array(),
  false,
  'all'
);

これをやると通常
wp-content/themes/(テーマ名)/css/about.css
を参照するはずが、
wp-admin/css/about.min.css
からcssを取ってくる。
このファイルは別に自分で生成したわけではなく、Wordpressをインストールした時点で入っている。

この問題は第一引数を"bio"に変えたら(自分は念のためaboutを含むファイル名から何から全部変えたが)解決した。
多分"about"は既に定義されているのだと思う。他にも"content"などの文字列を渡すと同様の問題が起こるらしい。

ちなみにwp_enqueue_script()で同様の問題が発生するかは特に検証していないが、問題の性質からするとあり得ると思う。

とりあえず名前だけ変えてみることをおすすめします。

0
0
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
0
0