Changes to attachment pages

As of WordPress 6.4, attachment pages for new WordPress installations are fully disabled.

Until WordPress 6.4 was released, WordPress created attachment pages by default for every attachment uploaded. On the vast majority of sites, these attachment pages don’t add any meaningful information. They do, however, exist, get indexed by search engines, and sometimes even rank in search results, leading to bad results for users and site owners.

This change introduces a wp_attachment_pages_enabled database option to control the attachment pages’ behavior:

  • On existing sites, the option is set to 1 on upgrade, so that attachment pages continue to work as is.
  • For new sites, the option is set to 0 by default, which means attachment pages are redirected to the attachment URLURL A specific web address of a website or web page on the Internet, such as a website’s URL www.wordpress.org.
  • Sites administrators who want to enable or disable the attachment pages can set the option to 1 or 0, respectively.

When attachment pages are disabled, the adminadmin (and super admin) link “View attachment page” changes to “View Media File”.

Setting the option

Via WP CLICLI Command Line Interface. Terminal (Bash) in Mac, Command Prompt in Windows, or WP-CLI for WordPress.

To test this change or if you just want to change it on a live site, you can use WP CLI. You would do so like this:

wp option set wp_attachment_pages_enabled 0|1

Via a pluginPlugin A plugin is a piece of software containing a group of functions that can be added to a WordPress website. They can extend functionality or add new features to your WordPress websites. WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress. These can be free in the WordPress.org Plugin Directory https://wordpress.org/plugins/ or can be cost-based plugin from a third-party

Another option is to use this small plugin built by @costdev during the development process that allows enabling the attachment pages through an admin bar item.

Via the admin options page

While this is not usually recommended, you can visit wp-admin/options.php on your site, search for wp_attachment_pages_enabled and change the option right there.

TracTrac An open source project by Edgewall Software that serves as a bug tracker and project management tool for WordPress. ticketticket Created for both bug reports and feature development on the bug tracker. #57913

Props to @joostdevalk for writing the dev notedev note Each important change in WordPress Core is documented in a developers note, (usually called dev note). Good dev notes generally include a description of the change, the decision that led to this change, and a description of how developers are supposed to work with that change. Dev notes are published on Make/Core blog during the beta phase of WordPress release cycle. Publishing dev notes is particularly important when plugin/theme authors and WordPress developers need to be aware of those changes.In general, all dev notes are compiled into a Field Guide at the beginning of the release candidate phase..

Props to @sabernhardt @bph and @webcommsat for peer review.

#6-4, #dev-notes, #dev-notes-6-4