{"id":34590,"date":"2013-07-11T14:47:15","date_gmt":"2013-07-11T09:17:15","guid":{"rendered":"https:\/\/www.quickonlinetips.com\/archives\/?p=34590"},"modified":"2026-10-13T13:42:13","modified_gmt":"2026-10-13T08:12:13","slug":"force-404-errors-wordpress","status":"publish","type":"post","link":"https:\/\/www.quickonlinetips.com\/archives\/2013\/07\/force-404-errors-wordpress\/","title":{"rendered":"How to Force 404 Errors in WordPress (and Use 410 for Deleted Pages)"},"content":{"rendered":"<p>Sometimes you need to force 404 errors in WordPress. Maybe you deleted thin or spammy pages, or old URLs with bad backlinks, and want search engines to drop them. When I <a href=\"https:\/\/www.quickonlinetips.com\/archives\/2013\/06\/delete-urls-with-bad-backlinks-to-remove-google-penalty\/\">deleted URLs with bad backlinks<\/a> to recover from a Google penalty, I found the unpublished pages still returned a 200 OK status. Here is how to make sure removed pages really return a 404 (or better, a 410) in WordPress in 2026.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-34603\" src=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/404-page.jpg\" alt=\"Force 404 errors in WordPress\" width=\"419\" height=\"258\" srcset=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/404-page.jpg 419w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/404-page-300x184.jpg 300w\" sizes=\"(max-width: 419px) 100vw, 419px\" \/><\/p>\n<p><strong>Quick answer:<\/strong> Trash or delete the post, then purge your page cache and CDN, and check the URL&#8217;s status code with an HTTP header checker or <code>curl -I<\/code>. If it still shows 200, use Rank Math&#8217;s or the Redirection plugin&#8217;s option to return <strong>410 Content Deleted<\/strong> (or 404) for that URL, or add a small <code>template_redirect<\/code> snippet that sends a 404 status.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_89 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6af50109a4b5d\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"ez-toc-cssicon\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #1a202c;color:#1a202c\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #1a202c;color:#1a202c\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6af50109a4b5d\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2013\/07\/force-404-errors-wordpress\/#404_vs_410_which_should_you_use\" >404 vs 410: which should you use?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2013\/07\/force-404-errors-wordpress\/#Why_WordPress_may_not_return_a_404\" >Why WordPress may not return a 404<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2013\/07\/force-404-errors-wordpress\/#How_to_force_a_404_or_410_in_WordPress\" >How to force a 404 or 410 in WordPress<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2013\/07\/force-404-errors-wordpress\/#Method_1_Rank_Math_Redirections\" >Method 1: Rank Math Redirections<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2013\/07\/force-404-errors-wordpress\/#Method_2_Redirection_plugin\" >Method 2: Redirection plugin<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2013\/07\/force-404-errors-wordpress\/#Method_3_A_code_snippet\" >Method 3: A code snippet<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2013\/07\/force-404-errors-wordpress\/#Check_that_it_worked\" >Check that it worked<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2013\/07\/force-404-errors-wordpress\/#Clean_up_after_removing_pages\" >Clean up after removing pages<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2013\/07\/force-404-errors-wordpress\/#FAQ\" >FAQ<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2013\/07\/force-404-errors-wordpress\/#Are_404_errors_bad_for_SEO\" >Are 404 errors bad for SEO?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2013\/07\/force-404-errors-wordpress\/#How_long_does_Google_take_to_drop_a_404_page\" >How long does Google take to drop a 404 page?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2013\/07\/force-404-errors-wordpress\/#What_is_a_soft_404\" >What is a soft 404?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"404_vs_410_which_should_you_use\"><\/span>404 vs 410: which should you use?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li><strong>404 Not Found:<\/strong> the page does not exist. Google drops it after recrawling a few times.<\/li>\n<li><strong>410 Gone:<\/strong> the page was removed on purpose. Google treats it as a slightly stronger signal and usually drops it faster.<\/li>\n<li><strong>301 Redirect:<\/strong> use this instead if a better page on the same topic exists, to keep visitors and link value.<\/li>\n<\/ul>\n<p>Learn more about <a href=\"https:\/\/www.quickonlinetips.com\/archives\/2014\/11\/http-410-error-pages-htaccess\/\">HTTP 410 error pages<\/a>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Why_WordPress_may_not_return_a_404\"><\/span>Why WordPress may not return a 404<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li><strong>Cached pages:<\/strong> LiteSpeed Cache, WP Rocket or a CDN can keep serving the old page with 200 OK until purged.<\/li>\n<li><strong>Redirect plugins:<\/strong> some plugins redirect every 404 to the homepage, which Google treats as a &#8220;soft 404&#8221;.<\/li>\n<li><strong>Attachment and archive pages:<\/strong> an image attachment or tag page may still exist for the old content.<\/li>\n<li><strong>Theme 404 template:<\/strong> a custom 404 page that returns 200 instead of 404.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"How_to_force_a_404_or_410_in_WordPress\"><\/span>How to force a 404 or 410 in WordPress<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"Method_1_Rank_Math_Redirections\"><\/span>Method 1: Rank Math Redirections<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>In <strong>Rank Math &gt; Redirections<\/strong>, add the old URL as the source and choose <strong>410 Content Deleted<\/strong> (or 451) as the type. No destination is needed.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Method_2_Redirection_plugin\"><\/span>Method 2: Redirection plugin<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Add a redirect for the URL and choose the action &#8220;Error (404)&#8221; or &#8220;Error (410)&#8221;.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Method_3_A_code_snippet\"><\/span>Method 3: A code snippet<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code>add_action( 'template_redirect', function () {\n    $gone = array( '\/old-page\/', '\/another-old-post\/' );\n    if ( in_array( $_SERVER['REQUEST_URI'], $gone, true ) ) {\n        global $wp_query;\n        $wp_query-&gt;set_404();\n        status_header( 404 );\n        nocache_headers();\n        include get_query_template( '404' );\n        exit;\n    }\n} );<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Check_that_it_worked\"><\/span>Check that it worked<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ol>\n<li>Purge your cache plugin and CDN.<\/li>\n<li>Run <code>curl -I https:\/\/example.com\/old-page\/<\/code> or use an online HTTP header checker. You should see <code>404 Not Found<\/code> or <code>410 Gone<\/code>.<\/li>\n<li>In Google Search Console, inspect the URL and check the Pages report for &#8220;Not found (404)&#8221;.<\/li>\n<\/ol>\n<h2><span class=\"ez-toc-section\" id=\"Clean_up_after_removing_pages\"><\/span>Clean up after removing pages<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li>Remove internal links to the deleted URLs. See how to <a href=\"https:\/\/www.quickonlinetips.com\/archives\/2020\/04\/find-remove-internal-broken-links\/\">find and remove broken internal links<\/a>.<\/li>\n<li>Remove them from your XML sitemap (SEO plugins do this automatically).<\/li>\n<li>Decide which other weak pages to prune; here is how to <a href=\"https:\/\/www.quickonlinetips.com\/archives\/2012\/02\/find-thin-content\/\">find thin content<\/a>.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"FAQ\"><\/span>FAQ<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"Are_404_errors_bad_for_SEO\"><\/span>Are 404 errors bad for SEO?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>No. 404s for pages that should not exist are normal. Only fix 404s for pages that should be live or have valuable links.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_long_does_Google_take_to_drop_a_404_page\"><\/span>How long does Google take to drop a 404 page?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Usually days to weeks, depending on how often Google crawls your site. 410 can be slightly faster.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"What_is_a_soft_404\"><\/span>What is a soft 404?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>A page that says &#8220;not found&#8221; but returns 200 OK, or redirects to an irrelevant page. Google reports these in Search Console.<\/p>\n<p>Have you pruned old content on your site? Share your results in the comments.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you need to force 404 errors in WordPress. Maybe you deleted thin or spammy pages, or old URLs with&#8230;<\/p>\n","protected":false},"author":4,"featured_media":34603,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[6],"tags":[52,49,17],"class_list":["post-34590","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blogging","tag-popular","tag-tutorials","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts\/34590","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/comments?post=34590"}],"version-history":[{"count":3,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts\/34590\/revisions"}],"predecessor-version":[{"id":65489,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts\/34590\/revisions\/65489"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/media\/34603"}],"wp:attachment":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/media?parent=34590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/categories?post=34590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/tags?post=34590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}