wp_sitemaps_get_max_urls()
云策文档标注
概述
wp_sitemaps_get_max_urls() 函数用于获取站点地图中URL的最大数量,通过过滤器 wp_sitemaps_max_urls 允许开发者自定义此限制。
关键要点
- 函数接受一个参数 $object_type,指定站点地图的对象类型(如 'post'、'term'、'user')。
- 返回一个整数,表示URL的最大数量,默认值为2000。
- 通过 apply_filters('wp_sitemaps_max_urls', 2000, $object_type) 实现,支持钩子自定义。
- 在 WordPress 5.5.0 版本中引入。
代码示例
function wp_sitemaps_get_max_urls( $object_type ) {
/**
* Filters the maximum number of URLs displayed on a sitemap.
*
* @since 5.5.0
*
* @param int $max_urls The maximum number of URLs included in a sitemap. Default 2000.
* @param string $object_type Object type for sitemap to be filtered (e.g. 'post', 'term', 'user').
*/
return apply_filters( 'wp_sitemaps_max_urls', 2000, $object_type );
}
原文内容
Gets the maximum number of URLs for a sitemap.
Parameters
$object_typestringrequired-
Object type for sitemap to be filtered (e.g.
'post','term','user').
Source
function wp_sitemaps_get_max_urls( $object_type ) {
/**
* Filters the maximum number of URLs displayed on a sitemap.
*
* @since 5.5.0
*
* @param int $max_urls The maximum number of URLs included in a sitemap. Default 2000.
* @param string $object_type Object type for sitemap to be filtered (e.g. 'post', 'term', 'user').
*/
return apply_filters( 'wp_sitemaps_max_urls', 2000, $object_type );
}
Hooks
- apply_filters( ‘wp_sitemaps_max_urls’, int $max_urls, string $object_type )
-
Filters the maximum number of URLs displayed on a sitemap.
Changelog
| Version | Description |
|---|---|
| 5.5.0 | Introduced. |