[Task]: Decide how Yoast SEO handles the WordPress 7.2 random content URLs

Open
#23,784 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 4 days

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
20/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
php, wordpress
Domain
backend, search

Research direction

Start by reading the wp_enable_random_content_redirect and pre_get_posts hooks named in the issue, then review Yoast SEO's Crawl optimization settings and rewrite-rule handling. Decide the defaults, noindex behavior, multisite setting changes, and post-type scope before implementation. Done means the behavior is shipped before WordPress 7.2, with updated Crawl optimization help and compatibility notes.

Written by the indexing model from the issue text.

Description

Context - Why was this issue created?

WordPress 7.2 adds random content URLs, announced in Your content is going to get more random (Trac ticket #64498). The feature is on by default.

A request to one of these URLs sends the visitor to a randomly picked published post:

  • /random/ picks any post.
  • /random/category/{slug}/, /random/tag/{slug}/ and other taxonomy archives pick a post from that term.
  • /random/author/{nicename}/ picks a post by that author.
  • /random/{post-type}/ picks a post of that post type.
  • Adding ?random to any archive or search URL does the same for that archive.

Post types take part when they are public and have an archive, unless they register with 'randomable' => false. Site owners can turn the feature off with the wp_enable_random_content_redirect filter.

What doesn't break for Yoast SEO: WordPress sends the redirect before our front-end output runs, so our titles, canonical URLs and schema don't run on these URLs. WordPress answers with a temporary redirect (HTTP 302) and an X-Robots-Tag: noindex, follow header. Premium redirects run earlier, so a redirect that a user sets up for /random/ still takes priority.

What can affect our users:

  • Content set to noindex in Yoast SEO can show up. WordPress picks the post with its own rules only: published, no password, and an eligible post type. It ignores the Yoast SEO noindex setting, both for a whole post type and for a single post. A post that a site owner hid from search engines can be reached through these URLs.
  • The site gets many more public URLs. Every category, tag and author archive gains a random version that bots can crawl.
  • Each request can be slow on large sites. WordPress picks the post by sorting the matching posts randomly in the database, which gets slower as the number of posts grows.
What is the goal of this issue?

Decide how Yoast SEO handles random content URLs, and ship the result before WordPress 7.2 is released.

What needs to be done to achieve the goal?

Evaluate the following:

  • A Crawl optimization toggle to remove random content URLs. It would return false on the wp_enable_random_content_redirect filter. This fits next to the existing toggles that remove feeds, shortlinks and emoji scripts.
  • Whether the toggle removes the URLs by default. Decide this for new installs and for existing sites on upgrade.
  • Respecting Yoast SEO noindex settings when the URLs stay enabled. When WordPress picks the random post, leave out post types and posts that are set to noindex in Yoast SEO.
    • A post set to index inside a post type set to noindex would be left out too. This matches the XML sitemap, which skips the whole post type and only reads the per-post setting to drop posts.
    • Noindex means "keep out of search results," not "hide from visitors." Some sites noindex a post type to keep thin pages out of Google but still want visitors to find them at random. Evaluate a filter, such as wpseo_random_content_exclude_noindexed, that lets those sites keep noindexed content in the selection, rather than a second toggle.
  • A second toggle to limit random content URLs to posts. When the URLs stay enabled, WordPress picks from every public post type with an archive, such as products or portfolio items. This toggle would restrict the pick to regular posts only, for sites that want the feature for their blog but not for their other content.
    • Evaluate how it combines with the noindex handling above, and whether /random/{post-type}/ URLs for other post types should then return a "not found" page.
  • Clearing the stored rewrite rules (the URL patterns WordPress saves in the database) when the setting changes. WordPress requires this after the filter's value changes. On multisite, this includes every site in the network when a network admin allows or disallows the setting.
    • Clearing every site while the network settings are saved can time out on networks with thousands of sites. Evaluate letting each site clear its own rules on its next request instead, by comparing a counter in the network settings with one in the site's settings.
  • Showing the toggle only on WordPress versions that support the feature. This includes the settings page, the network settings and the settings search.
  • Release timing. Ship before WordPress 7.2, and mention it in the WordPress 7.2 compatibility notes.
Does the issue still need UX or research?

Yes. Decide the toggle's placement and wording on the Crawl optimization page, and whether removing the URLs should be the default.

If available, what are the tips for fixing the problem or possible solutions?
  • Register the filter on every request, not only on the front end. WordPress also builds the rewrite rules during admin requests.
  • Use wp_is_random_content_query() in a pre_get_posts callback to change only the random selection query and leave all other queries untouched.
  • Yoast SEO already clears rewrite rules after every plugin upgrade, so stale /random/ rules disappear on update.
What is the expected result/behavior?

Site owners control random content URLs from the Crawl optimization settings. Content they set to noindex in Yoast SEO never shows up through these URLs.

Should documentation be added or updated for this change? And if so, where?

Yes. Update the Crawl optimization help article, and add a line to the WordPress 7.2 compatibility notes.

Dominant language
JavaScript
Stars
2k
Forks
988
Avg merge
3d 13h
Merged PRs (30d)
66

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Yoast/wordpress-seo

All issues in Yoast/wordpress-seo

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.