get_bloginfo

函数
get_bloginfo ( $show = '', $filter = 'raw' )
参数
  • (string) $show Optional. Site info to retrieve. Default empty (site name).
    Required:
    Default: (empty)
  • (string) $filter Optional. How to filter what is retrieved. Default 'raw'.
    Required:
    Default: 'raw'
返回值
  • (string) Mostly string values, might be empty.
定义位置
相关方法
get_bloginfo_rssbloginfoget_blog_listget_blog_postget_link
引入
0.71
弃用
-

get_bloginfo: 这个函数检索关于当前站点或多站点网络中当前站点的父站点的信息: 该函数接收一个参数,指定要检索的信息类型,如网站标题、描述、URL等。

检索关于当前网站的信息。

`$show’的可能值包括:

– ‘name’ – 网站标题(在设置> General中设定)。
– ‘description’- 网站标语(在设置> General中设置)。
– ‘wpurl’ – WordPress的地址(URL)(在设置> 常规中设置)。
– ‘url’ – 网站地址(URL)(在设置> General中设置)。
– ‘admin_email’ – 管理员的电子邮件(在设置> General中设置)。
– ‘charset’ -“页面和feeds的编码”(在Settings > Reading中设置)。
– ‘版本’ – 当前WordPress的版本
– html_type’ – 内容类型(默认:”text/html”)。主题和插件
可以使用{@see ‘pre_option_html_type’}过滤器覆盖默认值。
– ‘text_direction’ – 由网站语言决定的文本方向。
应该被用来代替
– ‘language’ – 当前网站的语言代码
– ‘styleheet_url’ – 活动主题的样式表的URL。一个活跃的子主题
将优先于这个值
– stylesheet_directory’ – 活动主题的目录路径。 一个活动的子主题
将会优先于这个值
– ‘template_url’ / ‘template_directory’ – 活动主题目录的URL。一个活跃的
子主题不会优先考虑这个值。
– ‘pingback_url’ – 回传的XML-RPC文件的URL(xmlrpc.php)。
– ‘atom_url’ – Atom feed URL (/feed/atom)
– ‘rdf_url’ – RDF/RSS 1.0馈送URL(/feed/rdf)
– ‘rss_url’ – RSS 0.92 feed URL (/feed/rss)
– ‘rss2_url’ – RSS 2.0的URL(/feed)
– ‘comments_atom_url’ – 评论的Atom feed URL (/comments/feed)
– ‘comments_rss2_url’ – 评论RSS2.0的URL(/comments/feed)

一些`$show’值已被弃用,在未来的版本中会被删除。这些选项将触发_deprecated_argument()函数。

弃用的参数包括:

– ‘siteurl’ – 使用’url’代替
– ‘home’ – 使用’url’代替

function get_bloginfo( $show = '', $filter = 'raw' ) {
	switch ( $show ) {
		case 'home':    // Deprecated.
		case 'siteurl': // Deprecated.
			_deprecated_argument(
				__FUNCTION__,
				'2.2.0',
				sprintf(
					/* translators: 1: 'siteurl'/'home' argument, 2: bloginfo() function name, 3: 'url' argument. */
					__( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s option instead.' ),
					'<code>' . $show . '</code>',
					'<code>bloginfo()</code>',
					'<code>url</code>'
				)
			);
			// Intentional fall-through to be handled by the 'url' case.
		case 'url':
			$output = home_url();
			break;
		case 'wpurl':
			$output = site_url();
			break;
		case 'description':
			$output = get_option( 'blogdescription' );
			break;
		case 'rdf_url':
			$output = get_feed_link( 'rdf' );
			break;
		case 'rss_url':
			$output = get_feed_link( 'rss' );
			break;
		case 'rss2_url':
			$output = get_feed_link( 'rss2' );
			break;
		case 'atom_url':
			$output = get_feed_link( 'atom' );
			break;
		case 'comments_atom_url':
			$output = get_feed_link( 'comments_atom' );
			break;
		case 'comments_rss2_url':
			$output = get_feed_link( 'comments_rss2' );
			break;
		case 'pingback_url':
			$output = site_url( 'xmlrpc.php' );
			break;
		case 'stylesheet_url':
			$output = get_stylesheet_uri();
			break;
		case 'stylesheet_directory':
			$output = get_stylesheet_directory_uri();
			break;
		case 'template_directory':
		case 'template_url':
			$output = get_template_directory_uri();
			break;
		case 'admin_email':
			$output = get_option( 'admin_email' );
			break;
		case 'charset':
			$output = get_option( 'blog_charset' );
			if ( '' === $output ) {
				$output = 'UTF-8';
			}
			break;
		case 'html_type':
			$output = get_option( 'html_type' );
			break;
		case 'version':
			global $wp_version;
			$output = $wp_version;
			break;
		case 'language':
			/*
			 * translators: Translate this to the correct language tag for your locale,
			 * see https://www.w3.org/International/articles/language-tags/ for reference.
			 * Do not translate into your own language.
			 */
			$output = __( 'html_lang_attribute' );
			if ( 'html_lang_attribute' === $output || preg_match( '/[^a-zA-Z0-9-]/', $output ) ) {
				$output = determine_locale();
				$output = str_replace( '_', '-', $output );
			}
			break;
		case 'text_direction':
			_deprecated_argument(
				__FUNCTION__,
				'2.2.0',
				sprintf(
					/* translators: 1: 'text_direction' argument, 2: bloginfo() function name, 3: is_rtl() function name. */
					__( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s function instead.' ),
					'<code>' . $show . '</code>',
					'<code>bloginfo()</code>',
					'<code>is_rtl()</code>'
				)
			);
			if ( function_exists( 'is_rtl' ) ) {
				$output = is_rtl() ? 'rtl' : 'ltr';
			} else {
				$output = 'ltr';
			}
			break;
		case 'name':
		default:
			$output = get_option( 'blogname' );
			break;
	}

	$url = true;
	if ( strpos( $show, 'url' ) === false &&
		strpos( $show, 'directory' ) === false &&
		strpos( $show, 'home' ) === false ) {
		$url = false;
	}

	if ( 'display' === $filter ) {
		if ( $url ) {
			/**
			 * Filters the URL returned by get_bloginfo().
			 *
			 * @since 2.0.5
			 *
			 * @param string $output The URL returned by bloginfo().
			 * @param string $show   Type of information requested.
			 */
			$output = apply_filters( 'bloginfo_url', $output, $show );
		} else {
			/**
			 * Filters the site information returned by get_bloginfo().
			 *
			 * @since 0.71
			 *
			 * @param mixed  $output The requested non-URL site information.
			 * @param string $show   Type of information requested.
			 */
			$output = apply_filters( 'bloginfo', $output, $show );
		}
	}

	return $output;
}

常见问题

FAQs
查看更多 >