The code in the provided GitHub Gist demonstrates how to extend Jetpack’s XML sitemap functionality to include all public custom post types (CPTs), including those registered via Advanced Custom Fields (ACF), without relying on the active theme. This approach offers several advantages:
✅ Advantages of Using a Theme-Independent MU Plugin
Decouples Sitemap Logic from Theme: By placing the code in a must-use (MU) plugin, the sitemap customization remains active regardless of theme changes, ensuring consistent sitemap behavior across theme updates or switches.
Automatic Inclusion of All Public CPTs: The get_dynamic_sitemap_post_types() function dynamically retrieves all public post types, including those registered by plugins like ACF, ensuring they are automatically added to the sitemap without manual updates.
Excludes Non-Relevant Post Types: The code filters out post types such as ‘attachment’, ‘revision’, and ‘nav_menu_item’, which are typically not needed in sitemaps, ensuring a cleaner and more relevant sitemap.
Persistent Across Plugin Updates: Since the customization is handled in an MU plugin, it remains unaffected by updates to Jetpack or other plugins, providing stability and reducing the risk of losing customizations.
Centralized Management: Managing sitemap customizations in an MU plugin allows for easier maintenance and troubleshooting, as all related code is consolidated in one location.
This method leverages Jetpack’s jetpack_sitemap_post_types filter to modify the list of post types included in the sitemap, aligning with best practices for extending Jetpack’s functionality. citeturn0search0
If you need assistance integrating this approach into your WordPress site or have further questions, feel free to ask.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters