do_robots() - WordPress 函数参考中文文档

返回介绍

do_robots()

发布于 2017-09-10 字数1856 浏览 814 评论 0

do_robots()

Display the robots.txt file content.


描述

The echo content should be with usage of the permalinks or for creating the robots.txt file.


源代码

File: wp-includes/functions.php

function do_robots() {
	header( 'Content-Type: text/plain; charset=utf-8' );

	/**
	 * Fires when displaying the robots.txt file.
	 *
	 * @since 2.1.0
	 */
	do_action( 'do_robotstxt' );

	$output = "User-agent: *\n";
	$public = get_option( 'blog_public' );
	if ( '0' == $public ) {
		$output .= "Disallow: /\n";
	} else {
		$site_url = parse_url( site_url() );
		$path = ( !empty( $site_url['path'] ) ) ? $site_url['path'] : '';
		$output .= "Disallow: $path/wp-admin/\n";
		$output .= "Allow: $path/wp-admin/admin-ajax.php\n";
	}

	/**
	 * Filters the robots.txt output.
	 *
	 * @since 3.0.0
	 *
	 * @param string $output Robots.txt output.
	 * @param bool   $public Whether the site is considered "public".
	 */
	echo apply_filters( 'robots_txt', $output, $public );
}

更新日志

Version 描述
2.1.0 Introduced.

相关函数

Uses

  • wp-includes/functions.php:
    do_robotstxt
  • wp-includes/functions.php:
    robots_txt
  • wp-includes/link-template.php:
    site_url()
  • wp-includes/plugin.php:
    do_action()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/option.php:
    get_option()
  • Show 1 more use
    Hide more uses


User Contributed Notes

上一篇:do_meta_boxes()

下一篇:do_settings_fields()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!