开发者 |
joemcgill
pacifika kburgoine tweetythierry swissspidy pbiron |
---|---|
更新时间 | 2020年8月11日 21:56 |
PHP版本: | 5.6 及以上 |
WordPress版本: | 5.5 |
版权: | GPLv2 or later |
版权网址: | 版权信息 |
core-sitemaps
folder to the /wp-content/plugins/
directory.If you update the WordPress settings to discourage search engines from indexing your site, sitemaps will be disabled.
Alternatively, use the wp_sitemaps_enabled
filter, or use remove_action( 'init', 'wp_sitemaps_get_server' );
to disable initialization of any sitemap functionality.
You can use the wp_sitemaps_register_providers
filter to disable sitemap generation for posts, users, or taxonomies.
You can use the wp_sitemaps_post_types
filter to disable sitemap generation for posts of a certain post type.
By default, only public posts will be represented in the sitemap.
Similarly, the wp_sitemaps_taxonomies
filter can be used to disable sitemap generation for certain taxonomies.
Example: Disabling sitemaps for the "page" post type
add_filter( 'wp_sitemaps_post_types', function( $post_types ) { unset( $post_types['page'] ); return $post_types; } );
Example: Disabling sitemaps for the "post_tag" taxonomy
add_filter( 'wp_sitemaps_taxonomies', function( $taxonomies ) { unset( $taxonomies['post_tag'] ); return $taxonomies; } );
The wp_sitemaps_posts_query_args
, wp_sitemaps_taxonomies_query_args
, and wp_sitemaps_users_query_args
filters can be used to modify the underlying queries. Using these queries, certain items can be excluded.
Example: Ensuring the page with ID 42 is not included
add_filter( 'wp_sitemaps_posts_query_args', function( $args ) { $args['post__not_in'] = isset( $args['post__not_in'] ) ? $args['post__not_in'] : array(); $args['post__not_in'][] = 42; return $args; } );
Example: Ensuring the category with ID 7 is not included
add_filter( 'wp_sitemaps_taxonomies_query_args', function( $args ) { $args['exclude'] = isset( $args['exclude'] ) ? $args['exclude'] : array(); $args['exclude'][] = 7; return $args; } );
Example: Ensuring the user with ID 1 is not included
add_filter( 'wp_sitemaps_users_query_args', function( $args ) { $args['exclude'] = isset( $args['exclude'] ) ? $args['exclude'] : array(); $args['exclude'][] = 1; return $args; } );
changefreq
, priority
, or lastmod
to a sitemap?You can use the wp_sitemaps_posts_entry
/ wp_sitemaps_users_entry
/ wp_sitemaps_taxonomies_entry
filters to add additional attributes like changefreq
, priority
, or lastmod
to single item in the sitemap.
Example: Adding the last modified date for posts
add_filter( 'wp_sitemaps_posts_entry', function( $entry, $post ) { $entry['lastmod'] = $post->post_modified_gmt; return $entry; }, 10, 2 );
Similarly, you can use the wp_sitemaps_index_entry
filter to add lastmod
on the sitemap index. Note: changefreq
and priority
are not supported on the sitemap index.
目前还不支持添加图片站点地图,但将来会添加支持,以便插件开发者在需要时可以添加。
Use the wp_sitemaps_max_urls
filter to adjust the maximum number of URLs included in a sitemap. The default value is 2000 URLs.
A variety of filters exist to allow you to adjust the styling:
wp_sitemaps_stylesheet_url
- Filter the URL for the sitemap stylesheet.wp_sitemaps_stylesheet_index_url
- Filter the URL for the sitemap index stylesheet.wp_sitemaps_stylesheet_content
- Filter the content of the sitemap stylesheet.wp_sitemaps_index_stylesheet_content
- Filter the content of the sitemap index stylesheet.wp_sitemaps_stylesheet_css
- Filter the CSS only for the sitemap stylesheet.changefreq
and priority
attributes for sitemaps?No. Those are optional fields in the sitemaps protocol and not typically consumed by search engines. Developers can still add those fields if they really want to.
XML sitemaps are first and foremost a discovery mechanism for content. Exposing the date the content was last modified is not needed for the majority of sites.