9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

何でWordpressは自身のURLを示す関数に `home_url` とか `site_url()` とか bloginfo('url')とかいっぱいあんの?

Posted at

Wordpressで自身のURLが欲しい時に調べてみたらいっぱい出てきた。

site_url()
home_url()
bloginfo('url')
bloginfo('wpurl')
bloginfo('siteurl')
bloginfo('home')

なんでやねん。何でそんなに多いねん。一個でいいですやん。

調べてみた

それぞれの違いとか使い方を調べてみました。

site_url()
General Settings の WordPress Address (URL) の項目の値

home_url()
General Settings の Site Address (URL) の項目の値

site_url() は plugins_url などの wp-admin 配下のアドレスも追跡できるけど、home_url() はできないらしい。

bloginfo()はget_option()のwrapperでしかないので

bloginfo('wpurl') は site_url() を参照して
bloginfo('url') は home_url() を参照してるだけ。

あと bloginfo('home'),bloginfo('siteurl') は 2.2 から deprecated 扱い。

参考

Function Reference/bloginfo « WordPress Codex
http://codex.wordpress.org/Function_Reference/bloginfo

functions - What's the difference between home_url() and site_url() - WordPress Answers
http://wordpress.stackexchange.com/questions/20294/whats-the-difference-between-home-url-and-site-url

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?