PHP code example of bonnier / wp-bonnier-sitemap

1. Go to this page and download the library: Download bonnier/wp-bonnier-sitemap library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bonnier / wp-bonnier-sitemap example snippets


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);

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

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);

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);

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

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

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

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

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