Skip to content

Disable attachment pages on legacy WordCamp sites#34

Closed
dd32 wants to merge 2 commits intoproductionfrom
fix/claude/1333-disable-attachment-pages-v2
Closed

Disable attachment pages on legacy WordCamp sites#34
dd32 wants to merge 2 commits intoproductionfrom
fix/claude/1333-disable-attachment-pages-v2

Conversation

@dd32
Copy link
Copy Markdown
Owner

@dd32 dd32 commented Mar 12, 2026

Summary

  • Forces wp_attachment_pages_enabled to 0 via pre_option filter in wcorg-misc.php
  • WordPress 6.4+ disables attachment pages on new installs, but legacy sites still have them enabled
  • When disabled, WordPress core automatically 301 redirects attachment page requests to the attachment file URL
  • This prevents SEO issues and spam on attachment pages like the example in the issue

Details

The fix is a single line: add_filter( 'pre_option_wp_attachment_pages_enabled', '__return_zero' );

This follows the same pattern already used for blog_public in the same file. WordPress core handles the redirect logic in wp-includes/canonical.php (line ~552) when this option is falsy.

Reference: https://make.wordpress.org/core/2023/10/16/changes-to-attachment-pages/

Test plan

  • Integration test verifying get_option( 'wp_attachment_pages_enabled' ) returns 0
  • Verify attachment page URLs return 301 redirects to the media file URL
  • Verify normal pages and posts are unaffected

Fixes WordPress#1333

🤖 Generated with Claude Code

Legacy WordCamp sites still have attachment pages enabled, causing SEO
issues and attracting spam. WordPress 6.4+ disables these on new installs
but existing sites need an explicit opt-out.

Force wp_attachment_pages_enabled to 0 via pre_option filter, which
triggers WordPress core built-in 301 redirect to the attachment file URL.

Fixes WordPress#1333

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dd32
Copy link
Copy Markdown
Owner Author

dd32 commented Mar 24, 2026

No need to add the tests here.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dd32
Copy link
Copy Markdown
Owner Author

dd32 commented Mar 24, 2026

Filed upstream: WordPress#1682

@dd32 dd32 closed this Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant