• Resolved a1exus

    (@a1exus)


    hello world!

    I’m running into an issue with Jetpack’s sitemap feature on my WordPress site. I’ve created a custom post type using Advanced Custom Fields (ACF), and the posts for this type aren’t showing up in the generated sitemap.xml.

    please advise

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support Swish (a11n)

    (@swisha8c)

    Hi @a1exus,

    To add a custom post type to the Jetpack sitemap, you will need to use the jetpack_sitemap_post_types filter to add it manually. See the Jetpack developer reference for more details: https://developer.jetpack.com/hooks/jetpack_sitemap_post_types/

    Thread Starter a1exus

    (@a1exus)

    Hello Swish and thank you for your message, I really appreciate it!

    now, I’ve added the following php code to wp-content/mu-plugins/custom-jetpack-sitemap.php file:

    <?php
    /*
    Plugin Name: Custom Post Types in Jetpack Sitemap (MU)
    Description: Adds "sponsor" post type to the Jetpack sitemap.
    Version: 1.0
    Author: ChatGPT
    */

    if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
    }

    function custom_jetpack_sitemap_post_types( $post_types ) {
    if ( post_type_exists( 'sponsor' ) ) {
    $post_types[] = 'sponsor';
    }
    return $post_types;
    }
    add_filter( 'jetpack_sitemap_post_types', 'custom_jetpack_sitemap_post_types' );

    assuming the code is actually correct, how can one verifies that it actually _is_ working and my custom post_type got into sitemap?

    • This reply was modified 1 month, 1 week ago by a1exus.
    • This reply was modified 1 month, 1 week ago by a1exus.
    • This reply was modified 1 month, 1 week ago by a1exus.
    Plugin Support Chatoxz (a11n)

    (@chatoxz)

    Hi there,

    Thanks for the additional questions.

    To verify if your custom post type is included in the sitemap, you can check the sitemap file directly by visiting?https://youarebetter.com/sitemap.xml?in your browser. Navigate to the sitemap:?https://youarebetter.com/sitemap-1.xml?and look for entries related to your “sponsor” post type. If they appear, your code will work correctly.

    I can see one already: https://youarebetter.com/sponsor/echo-hydrogen-water/, but please let us know if everything works correctly.

    Thank you!

    Thread Starter a1exus

    (@a1exus)

    I checked my sitemap but don’t see my two new ACF post types.

    $ cat ./wp-content/mu-plugins/custom-jetpack-sitemap-20250317.php
    <?php
    /*
    Plugin Name: Dynamic Post Types in Jetpack Sitemap (MU)
    Description: Dynamically includes all registered public post types (including ACF types) in the Jetpack XML sitemap.
    Version: 1.4
    Author: ChatGPT
    */

    if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
    }

    /**
    * Get all registered public post types for Jetpack sitemap.
    *
    * @return array List of valid public post types.
    */
    function get_dynamic_sitemap_post_types() {
    static $cached_types = null;
    if ( is_null( $cached_types ) ) {
    $excluded_post_types = ['attachment', 'revision', 'nav_menu_item'];
    $all_post_types = get_post_types(['public' => true], 'names');
    $cached_types = array_diff($all_post_types, $excluded_post_types);
    }
    return $cached_types;
    }

    /**
    * Add public post types to Jetpack sitemap.
    *
    * @param array $post_types Existing post types in the sitemap.
    * @return array Modified list of post types.
    */
    function dynamic_jetpack_sitemap_post_types( $post_types ) {
    return array_unique(array_merge($post_types, get_dynamic_sitemap_post_types()));
    }

    /**
    * Hook into Jetpack sitemap filter once plugins are fully loaded.
    */
    add_action('plugins_loaded', function() {
    if ( class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'is_module_active' ) && Jetpack::is_module_active( 'sitemaps' ) ) {
    add_filter( 'jetpack_sitemap_post_types', 'dynamic_jetpack_sitemap_post_types' );
    }
    });
    $
    • This reply was modified 6 days, 12 hours ago by a1exus.
    Plugin Support Josh (a11n)

    (@vitkory)

    Howdy @a1exus – sitemaps are usually updated every 12 hours, are you able to generate a new sitemap request on your end to see if those new custom post types are listed?

    Plugin Support Josh (a11n)

    (@vitkory)

    Howdy @a1exus – sitemaps are updated around every 12 hours with new content. Are you able to generate a new sitemap request on your end to see if those new custom post types are listed?

    Thread Starter a1exus

    (@a1exus)

    i’ve got it to work (again) latest (working) php code is available at: https://gist.github.com/a1exus/30be3a17ef0b91308843240626a97428

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.