Repository navigation
Add a 410 template for removed lessons, courses and tutorials - #3696
Open
muneeb-ashraf wants to merge 1 commit into
Open
muneeb-ashraf wants to merge 1 commit into
muneeb-ashraf wants to merge 1 commit into
Conversation
Retired content is set to draft or trashed rather than deleted, so its URLs returned a 404. When a 404 request matches a draft or trashed lesson, course, lesson plan or tutorial, send a 410 status and use a new 410 template. It reuses the 404 layout and asks visitors to tell us what they were looking for. Fixes WordPress#2914. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W6LxjEQnP4PPgXXvAM3M2F
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.
Fixes #2914.
What
Retired content on Learn is set to draft (or trashed) rather than deleted, as described in #2496. Its URLs currently return a
404, which tells search engines the page might come back. This sends a410 Goneinstead, with a dedicated template.functions.php: a404_template_hierarchyfilter. When a 404 request names a draft or trashedcourse,lesson,lesson-planorwporg_workshop(tutorial) post, it sendsstatus_header( 410 )and puts the410template first. Trashed posts are matched through their__trashedslug suffix.templates/410.html+patterns/410-page-content.php: the 404 layout with a "This content is no longer available." heading, the search block, and the line suggested in the issue: "If you were looking for something specific, please let us know", linking to/report-content-feedback/.Nothing changes for published content, URLs that never existed, private posts, or other post types. Existing redirects in
wporg_learn_redirect_old_urls()still run first, since they fire ontemplate_redirect, before the template is chosen.The wording is a first pass based on the suggestion in the issue. I'm happy to change it.
Testing
I tested the two new functions against WordPress trunk with a throwaway PHPUnit harness. It pulls them out of
functions.phpand registers the post types with Learn's rewrite slugs:/tutorial/old-tutorial/wporg_workshop410,404/lesson/old-lesson/lesson410,404/course/old-course/course410,404/lesson/never-existed/404/lesson/private-lesson/lesson404/old-post/post404/lesson/live-lesson/Without the filter, the first three cases fail and the rest still pass. PHPCS passes on the changed files with the repo's ruleset.
To check after deploy:
curl -sIon the URL of any drafted tutorial should returnHTTP/2 410.AI assistance
🤖 Generated with Claude Code
https://claude.ai/code/session_01W6LxjEQnP4PPgXXvAM3M2F