Disable attachment pages on legacy WordCamp sites#34
Closed
dd32 wants to merge 2 commits intoproductionfrom
Closed
Disable attachment pages on legacy WordCamp sites#34dd32 wants to merge 2 commits intoproductionfrom
dd32 wants to merge 2 commits intoproductionfrom
Conversation
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>
Owner
Author
|
No need to add the tests here. |
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Owner
Author
|
Filed upstream: WordPress#1682 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
wp_attachment_pages_enabledto0viapre_optionfilter inwcorg-misc.phpDetails
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_publicin the same file. WordPress core handles the redirect logic inwp-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
get_option( 'wp_attachment_pages_enabled' )returns0Fixes WordPress#1333
🤖 Generated with Claude Code