Page That Wouldn’t Go Away
Sometimes, WordPress holds onto pages even after you delete them, causing a frustrating experience where the page continues to appear despite being removed.
This happened to me with a page called Snippets, and after troubleshooting for hours, I finally figured out how to get rid of it. Here’s what happened and how you can fix it if you ever run into the same issue.
The Problem
I had created a WordPress page called Snippets and later decided to delete it. However, even after removing it from the Pages section in the WordPress dashboard, it still showed up at /snippets/
. Worse yet, the page template I had deleted was still listed as an option when creating a new page. No matter what I did, the page refused to go away.
Step 1: Checking If the Page Was Really Gone
First, I checked whether WordPress was still tracking the deleted page. Using WP-CLI, I ran:
wp post list --post_type=page --title="Snippets"
This command lists all posts of type page that have the title “Snippets.” Pages in WordPress are a specific post type (post_type=page
), separate from other post types like posts or custom post types.
To check if my custom post type (snippet) was still active, I ran:
wp post list --post_type=snippet
This lists all posts that belong to the snippet
post type. Unlike post_type=page
, which retrieves only pages, post_type=snippet
retrieves all posts created under the custom post type snippet
. If you’re using a custom post type and want to check if any entries still exist, use this command.
To summarize:
wp post list --post_type=page --title="Snippets"
→ Lists pages with the title “Snippets.”wp post list --post_type=snippet
→ Lists all posts that belong to thesnippet
custom post type.
If you find an entry that should no longer exist, you can delete it using:
wp post delete <ID> --force
Where <ID>
is the post ID returned by the previous command.
Step 2: Forcing Deletion
Since WordPress was still tracking the page, I manually deleted it using:
wp post delete 133 --force
This instantly removed the page. Finally, I could visit /snippets/
and see a 404 error, confirming that WordPress had let go of the page.
Step 3: Clearing Cache and Permalinks
Even after deleting the page, I wanted to ensure that WordPress and the browser weren’t caching any old versions. To do this, I ran:
wp cache flush
wp rewrite flush
Additionally, I went to Settings → Permalinks in the WordPress dashboard and clicked Save Changes to refresh the permalink structure.
Step 4: Verifying That the Page Template Was Gone
Another issue was that my old, deleted page template was still showing up in the “Template” dropdown when creating a new page. To force WordPress to refresh its list of available templates, I added this function in functions.php
:
function refresh_templates() {
wp_cache_delete('theme_page_templates', 'themes');
}
add_action('init', 'refresh_templates');
After reloading the admin panel and removing this function, the template list finally updated, and the deleted template was no longer listed.
Step 5: Ensuring WordPress Wasn’t Auto-Generating an Archive
Since Snippets was also a custom post type (snippet
), WordPress had automatically created an archive at /snippets/
. To prevent this from happening again, I modified my functions.php
file to disable the archive:
function modify_snippet_post_type() {
$args = array(
'public' => true,
'show_in_rest' => true,
'has_archive' => false, // Disable archive
'rewrite' => array('slug' => 'snippets'),
'supports' => array('title', 'editor'),
);
register_post_type('snippet', $args);
}
add_action('init', 'modify_snippet_post_type', 11);
After running another wp rewrite flush
, the /snippets/
archive was gone for good.
Final Thoughts
This experience showed me that WordPress doesn’t always delete things completely, and sometimes pages or templates get stuck. If you ever find yourself dealing with a “ghost” page that refuses to go away, follow these steps:
- Check if the page still exists using
wp post list --post_type=page
. - Check if a custom post type still exists using
wp post list --post_type=snippet
. - Force-delete it with
wp post delete <ID> --force
. - Flush cache and permalinks using
wp cache flush
andwp rewrite flush
. - Remove old templates by clearing the template cache.
- Disable auto-generated archives for custom post types if necessary.
By following these steps, you can ensure that when you delete something in WordPress, it actually stays deleted! 🚀
Have you ever run into a similar issue? Let me know in the comments how you fixed it!