bonnier/wp-bonnier-sitemap

Willow平台上的Sitemap插件

安装次数: 2,662

依赖项: 1

建议者: 0

安全: 0

星标: 0

关注者: 10

分支: 0

开放问题: 1

类型:wordpress-plugin


README

WordPress中处理Sitemap的插件

此插件将监视所有公开的WP_Post类型,

过滤器

此插件为WordPress网站的开发商提供了一些过滤器,以便自定义验证和处理要由该插件处理的内容。

WpBonnierSitemap::FILTER_ALLOWED_POST_TYPES = 'sitemap_allowed_post_types'

此过滤器允许您删除或添加由Sitemap插件允许的帖子类型,因此将监听哪些帖子类型的变化。

add_filter('sitemap_allowed_post_types', function(array $postTypes) {
    // Don't handle sitemaps for the page post type.
    return array_filter($postTypes, function(string $postType) {
        return $postType !== 'page';
    });
}, 10);

WpBonnierSitemap::FILTER_POST_ALLOWED_IN_SITEMAP = 'post_allowed_in_sitemap'

此过滤器允许您篡改是否将WP_Post放入Sitemap的验证。

默认值:true

add_filter('post_allowed_in_sitemap', function (bool $allowed, \WP_Post $post) {
    if ($post->post_type !== 'page') {
        $allowed = false;
    }
    return $allowed;
}, 10, 2);

WpBonnierSitemap::FILTER_POST_TAG_MINIMUM_COUNT = 'post_tag_minimum_count'

此过滤器允许您定义一个标签需要附加的最少帖子数,以便将其包含在Sitemap中。

默认值:5

add_filter('post_tag_minimum_count', function (int $count) {
    // For SEO purposes, our sitemap cannot have less than 10 posts for tag pages.
    return 10;
}, 10);

WpBonnierSitemap::FILTER_USER_MINIMUM_COUNT = 'user_minimum_count'

此过滤器允许您定义一个用户需要附加的最少帖子数,以便将其包含在Sitemap中。

默认值:5

add_filter('user_minimum_count', function (int $count) {
    // For SEO purposes, our sitemap cannot have less than 10 posts for user pages.
    return 10;
}, 10);

WpBonnierSitemap::FILTER_POST_PERMALINK = 'sitemap_post_permalink'

此过滤器允许您更改正在保存的帖子的生成永久链接。

add_filter('sitemap_post_permalink', function (string $permalink, \WP_Post $post) {
    return $permalink;
}, 10, 2);

WpBonnierSitemap::FILTER_CATEGORY_PERMALINK = 'sitemap_category_permalink'

此过滤器允许您更改正在保存的类别的生成永久链接。

add_filter('sitemap_category_permalink', function (string $permalink, \WP_Term $category) {
    return $permalink;
}, 10, 2);

WpBonnierSitemap::FILTER_TAG_PERMALINK = 'sitemap_tag_permalink'

此过滤器允许您更改正在保存的post_tag的生成永久链接。

add_filter('sitemap_tag_permalink', function (string $permalink, \WP_Term $tag) {
    return $permalink;
}, 10, 2);

WpBonnierSitemap::FILTER_TAG_ALLOWED_IN_SITEMAP = 'tag_allowed_in_sitemap'

此过滤器允许您篡改是否将WP_Term放入Sitemap的验证。

默认值:true

add_filter('tag_allowed_in_sitemap', function (bool $allowed, \WP_Term $tag) {
    if ($tag->taxonomy !== 'post_tag') {
            $allowed = false;
        }
        return $allowed;
}, 10, 2);

WpBonnierSitemap::FILTER_ALLOW_USER_IN_SITEMAP = 'allow_user_in_sitemap'

此过滤器允许您为将用户注册到Sitemap表中应用自己的规则。

add_filter('allow_user_in_sitemap', function (bool $allowInSitemap, int $userID, \WP_User $user) {
    return $allowInSitemap;
}, 10, 3);