^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 5年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云1核2g仅需102元/年,今日10点开抢

wordpress函数bloginfo()用法示例

bloginfo( string $show = '' )

Displays information about the current site.


描述


参数

$show

(string)
(Optional)
Site information to display.

Default value: ”


源代码

File: wp-includes/general-template.php

function bloginfo( $show = '' ) {
	echo get_bloginfo( $show, 'display' );
}

更新日志

Version 描述
0.71 Introduced.

More Information

Displays information about your site, mostly gathered from the information you supply in your User Profile and General Settings WordPress Administration Screens. It can be used anywhere within a template file. This always prints a result to the browser. If you need the values for use in PHP, use get_bloginfo().

Possible values for $show

  • name‘ – Displays the “Site Title” set in Settings > General. This data is retrieved from the “blogname” record in the wp_options table.
  • 描述‘ – Displays the “Tagline” set in Settings > General. This data is retrieved from the “blog 描述” record in the wp_options table.
  • wpurl‘ – Displays the “WordPress address (URL)” set in Settings > General. This data is retrieved from the “siteurl” record in the wp_options table. Consider echoing site_url() instead, especially for multi-site configurations using paths instead of subdomains (it will return the root site not the current sub-site).
  • url‘ – Displays the “Site address (URL)” set in Settings > General. This data is retrieved from the “home” record in the wp_options table. Consider echoing home_url() instead.
  • admin_email‘ – Displays the “E-mail address” set in Settings > General. This data is retrieved from the “admin_email” record in the wp_options table.
  • charset‘ – Displays the “Encoding for pages and feeds” set in Settings > Reading. This data is retrieved from the “blog_charset” record in the wp_options table. Note: this parameter always echoes “UTF-8”, which is the default encoding of WordPress.
  • version‘ – Displays the WordPress Version you use. This data is retrieved from the $wp_version variable set in wp-includes/version.php.
  • html_type‘ – Displays the Content-Type of WordPress HTML pages (default: “text/html”). This data is retrieved from the “html_type” record in the wp_options table. Themes and plugins can override the default value using the pre_option_html_type filter.
  • text_direction‘ – Displays the Text Direction of WordPress HTML pages. Consider using is_rtl() instead.
  • language‘ – Displays the language of WordPress.
  • stylesheet_url‘ – Displays the primary CSS (usually style.css) file URL of the active theme. Consider echoing get_stylesheet_uri() instead.
  • stylesheet_directory‘ – Displays the stylesheet directory URL of the active theme. (Was a local path in earlier WordPress versions.) Consider echoing get_stylesheet_directory_uri() instead.
  • template_url‘ / ‘template_directory‘ – URL of the active theme’s directory. Within child themes, both get_bloginfo(‘template_url’) and get_template() will return the parent theme directory. Consider echoing get_template_directory_uri() instead (for the parent template directory) or get_stylesheet_directory_uri() (for the child template directory).
  • pingback_url‘ – Displays the Pingback XML-RPC file URL (xmlrpc.php).
  • atom_url‘ – Displays the Atom feed URL (/feed/atom).
  • rdf_url‘ – Displays the RDF/RSS 1.0 feed URL (/feed/rfd).
  • rss_url‘ – Displays the RSS 0.92 feed URL (/feed/rss).
  • rss2_url‘ – Displays the RSS 2.0 feed URL (/feed).
  • comments_atom_url‘ – Displays the comments Atom feed URL (/comments/feed).
  • comments_rss2_url‘ – Displays the comments RSS 2.0 feed URL (/comments/feed).
  • siteurl‘ – Deprecated since version 2.2. Echo home_url(), or use bloginfo(‘url’).
  • home‘ – Deprecated since version 2.2. Echo home_url(), or use bloginfo(‘url’).

相关函数

Uses

  • wp-includes/general-template.php:
    get_bloginfo()

Used By

  • wp-includes/customize/class-wp-customize-site-icon-control.php:
    WP_Customize_Site_Icon_Control::content_template()
  • wp-admin/includes/class-wp-press-this.php:
    WP_Press_This::html()
  • wp-login.php:
    login_header()
  • wp-admin/includes/template.php:
    _wp_admin_html_begin()
  • wp-admin/includes/template.php:
    iframe_header()
  • wp-admin/includes/media.php:
    wp_iframe()
  • wp-admin/custom-header.php:
    Custom_Image_Header::step_1()
  • wp-includes/media-template.php:
    wp_print_media_templates()
  • Show 3 more used by
    Hide more used by


User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 5You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Show Blog Title

    Display your blog’s title in a tag.

    
    <h1><?php bloginfo( 'name' ); ?></h1>
    
  2. Show Blog 描述

    Displays the tagline of your blog as set in Settings > General.

    <p><?php bloginfo('描述'); ?> </p>

    If using bloginfo as a variable, for example:$url = bloginfo('url'); it will return null. This is because bloginfo() echos the result immediately. So if you want to use any of the bloginfo() parameters as variables use get_bloginfo(). This function returns the result as a string.

    Example output

    In this example case, the Site Address (URL) is shown as http://www.example.com/home, and the WordPress address (URL) is displayed as http://www.example.com/home/wp.

    Please note that directory URLs are missing trailing slashes.

    
    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
    描述          = Just another WordPress blog
    home                 = http://www.example.com/home (DEPRECATED! use url option instead)
    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 (DEPRECATED! use url option instead)
    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
    

    Show Blog Title in Link

    Displays your blog’s title in a link.

    <a href="<?php bloginfo('url'); ?>" title="<?php bloginfo('name'); ?>"><?php bloginfo('name'); ?></a>

    Show Character Set

    Displays the character set your blog is using (e.g. “utf-8”).
    NOTE: In version 3.5 and later, default character encoding is set to UTF-8 and is not configurable from the Administration Screen.

    <p>Character set: <?php bloginfo('charset'); ?> </p>

    Practical example that could be used as it is in themes. Hides 描述 if empty.

    <?php if ( get_bloginfo( '描述' )  !== '' ) { ?>
    	<a class="site-描述"><?php bloginfo( '描述' ); ?></a>
    <?php } ?>

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈