Skip to content

Add yearly and monthly sitemap organization for large sites#724

Draft
Copilot wants to merge 5 commits intomasterfrom
copilot/fix-649
Draft

Add yearly and monthly sitemap organization for large sites#724
Copilot wants to merge 5 commits intomasterfrom
copilot/fix-649

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 25, 2025

This PR implements a new sitemap feature that organizes content by publication year and month, similar to the approach used by Metro.co.uk. This is particularly beneficial for large sites like news websites that host substantial amounts of historical content.

Key Features

Yearly/Monthly Sitemap Organization:

  • When enabled, the main sitemap.xml becomes an index that links to yearly or monthly sitemaps
  • URLs like sitemap.xml?yyyy=2024 show all posts from 2024
  • URLs like sitemap.xml?yyyy=2024&m=12 show posts from December 2024
  • Maintains existing query limits and honors all current settings

Benefits:

  • Optimized crawl budget - Search engines can focus on newer content while still indexing older content efficiently
  • Faster generation - Individual yearly/monthly sitemaps are smaller and generate faster
  • Better cache efficiency - Each time period can be cached independently

Implementation Details

Settings & UI:

  • Added "Use yearly sitemaps" option (hidden when optimized sitemap is disabled)
  • Added "Use monthly sitemaps" sub-option (hidden until yearly is enabled)
  • Proper JavaScript visibility toggles following existing patterns
  • Both options default to disabled for backward compatibility

Backend Changes:

  • Enhanced Registry::_init() to capture and sanitize $_GET parameters
  • Modified Base::generate_sitemap() to accept year/month filtering parameters
  • Added intelligent date filtering using WordPress date_query for efficient database queries
  • Implemented per-period caching with unique cache keys (e.g., base_2024_12)

URL Structure:

# Main sitemap (when yearly enabled) - shows sitemap index
/sitemap.xml

# Yearly sitemap - shows all posts from 2024
/sitemap.xml?yyyy=2024

# Monthly sitemap - shows posts from December 2024
/sitemap.xml?yyyy=2024&m=12

Parameter Sanitization:

  • Years: 4-digit format (1900-2099 range)
  • Months: 1-2 digit format (1-12 range)
  • Invalid parameters are safely ignored

Developer Features

  • New public method: \The_SEO_Framework\Sitemap\Registry::get_sitemap_parameters() - Gets sanitized year and month parameters
  • New filter: the_seo_framework_sitemap_index_schemas - Filter sitemap index XML schemas
  • Backward compatible - No changes to existing functionality when feature is disabled

Testing

All modified files pass PHP syntax validation. The implementation includes comprehensive parameter sanitization with proper regex patterns and follows WordPress coding standards.

Fixes #649.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits June 25, 2025 13:05
Co-authored-by: sybrew <7662236+sybrew@users.noreply.github.com>
Co-authored-by: sybrew <7662236+sybrew@users.noreply.github.com>
Co-authored-by: sybrew <7662236+sybrew@users.noreply.github.com>
Co-authored-by: sybrew <7662236+sybrew@users.noreply.github.com>
Copilot AI changed the title [WIP] Sitemap for Large sites with filter date/year Add yearly and monthly sitemap organization for large sites Jun 25, 2025
Copilot AI requested a review from sybrew June 25, 2025 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sitemap for Large sites with filter date/year

2 participants