Custom Post Type Not Appearing in Jetpack Sitemap
-
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]
-
Hi @a1exus,
To add a custom post type to the Jetpack sitemap, you will need to use the
jetpack_sitemap_post_typesfilter to add it manually. See the Jetpack developer reference for more details: https://developer.jetpack.com/hooks/jetpack_sitemap_post_types/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?
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.xmlin 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!
-
This reply was modified 1 year, 1 month ago by
Chatoxz (a11n).
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 1 year ago by
a1exus.
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?
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?
i’ve got it to work (again) latest (working) php code is available at: https://gist.github.com/a1exus/30be3a17ef0b91308843240626a97428
Hi there,
Thanks for letting us know. We are glad we were able to help.
If Jetpack has been helpful to you, please take a moment to leave us a review. Your feedback not only helps us improve our product but also helps other potential users make informed decisions.
Cheers,
-
This reply was modified 1 year, 1 month ago by
The topic ‘Custom Post Type Not Appearing in Jetpack Sitemap’ is closed to new replies.