原文:https://developer.wordpress.org/reference/functions/bloginfo/
使用
<?php bloginfo( $show ); ?>
參數
$show (字元串string) (可選)你需要輸出的信息的關鍵詞。
默認: name
- 『name『 – 顯示在 設置 > 常規 中設置的「站點標題」。 該數據是從 wp_options 這個數據表中檢索到的 「blogname」記錄。
- 『description『 – 顯示在 設置 > 常規 中設置的「副標題」。該數據是從 wp_options 這個數據表中檢索到的 「blogdescription」 記錄。
- 『wpurl『 – 顯示在 設置 > 常規 中設置的 「WordPress 地址 (URL)」。該數據是從 wp_options 這個數據表中檢索到的 「siteurl」 記錄。 可以考慮使用 site_url() 來代替,尤其是在使用 子目錄路徑方式,而不是使用 子域名 來配置多站點時(bloginfo將返回根網站的URL,而不是子站點的URL)。
- 『siteurl『 / 『url『 – 顯示在 設置 > 常規 中設置的 「站點地址(URL)」)」。該數據是從 wp_options 這個數據表中檢索到的 「home」記錄。 可以考慮使用 home_url() 代替。
- 『admin_email』 – 顯示在 設置 > 常規 中設置的 「電子郵件地址」。該數據是從 wp_options 這個數據表中檢索到的 「admin_email」記錄。
- 『charset』 – 顯示在 設置 > 常規 中設置的「頁面和feed的編碼」。該數據是從 wp_options 這個數據表中檢索到的」blog_charset」 記錄。(註:3.5.1+好像已經沒有這個選項了)
- 『version』 – 顯示你當前使用的 WordPress 版本。該數據是在 wp-includes/version.php 檢索到的 $wp_version 這個欄位的值。
- 『html_type』 – 顯示WordPress HTML 頁面中的內容類型(默認: 「text/html」)。該數據可以從 wp_options 這個數據表中檢索到的 「html_type」 記錄。主題和插件可以通過使用 pre_option_html_type 過濾器覆蓋默認值。
- 『text_direction』 – 顯示 WordPress HTML 頁面的文本方向。可以考慮使用 is_rtl() 代替。
- 『language』 – 顯示WordPress的語言。
- 『stylesheet_url』 – 顯示當前使用的主題的 CSS文件(通常為 style.css)路徑。可以考慮使用 get_stylesheet_uri() 代替。
- 『stylesheet_directory』 – 顯示當前使用的主題的樣式表路徑。可以考慮使用 get_stylesheet_directory_uri() 代替。
- 『template_url』 / 『template_directory』 – 當前主題的 URL 路徑 。在子主題中, get_bloginfo(『template_url』) 和 get_template() 都將返回父主題的目錄。可以考慮使用 get_template_directory_uri() (用於父主題目錄)或get_stylesheet_directory_uri() (用於子主題目錄)代替。
- 『pingback_url』 – 顯示通告文件 XML-RPC 的URL (xmlrpc.php)
- 『atom_url』 – 顯示 Atom feed URL (/feed/atom)
- 『rdf_url』 – 顯示 RDF/RSS 1.0 feed URL (/feed/rfd).
- 『rss_url』 – 顯示 RSS 0.92 feed URL (/feed/rss).
- 『rss2_url』 – 顯示 RSS 2.0 feed URL (/feed).
- 『comments_atom_url』 – 顯示評論的 Atom feed URL (/comments/feed).
- 『comments_rss2_url』 – 顯示評論的 RSS 2.0 feed URL (/comments/feed).
例子
顯示博客標題
<h1><?php bloginfo('name'); ?></h1>
顯示帶鏈接的博客標題
<a href="<?php bloginfo('url'); ?>" title="<?php bloginfo('name'); ?>"><?php bloginfo('name'); ?></a>
顯示字符集
對應:設置 > 常規 中設置的「站點語言」
<p>Character set: <?php bloginfo('charset'); ?> </p>
顯示博客描述
對應:設置 > 常規 中設置的「副標題」
<p><?php bloginfo('description'); ?> </p>
其他
admin_email = admin@example.com
atom_url = http://www.example.com/home/feed/atom
charset = UTF-8
comments_atom_url = http://www.example.com/home/comments/feed/atom
comments_rss2_url = http://www.example.com/home/comments/feed
description = Just another WordPress blog
home = http://www.example.com/home (已棄用!使用 url 替代)
html_type = text/html
language = en-US
name = Testpilot
pingback_url = http://www.example.com/home/wp/xmlrpc.php
rdf_url = http://www.example.com/home/feed/rdf
rss2_url = http://www.example.com/home/feed
rss_url = http://www.example.com/home/feed/rss
siteurl = http://www.example.com/home (已棄用!使用 url 替代)
stylesheet_directory = http://www.example.com/home/wp/wp-content/themes/largo
stylesheet_url = http://www.example.com/home/wp/wp-content/themes/largo/style.css
template_directory = http://www.example.com/home/wp/wp-content/themes/largo
template_url = http://www.example.com/home/wp/wp-content/themes/largo
text_direction = ltr
url = http://www.example.com/home
version = 3.5
wpurl = http://www.example.com/home/wp
注
輸出的url鏈接是不帶最後的斜線的!
XXX()都是用來直接在瀏覽器中輸出內容;如果你需要在PHP中返回值的話,那麼請用 get_XXX()。