{"id":46619,"date":"2026-10-10T17:17:38","date_gmt":"2026-10-10T17:17:38","guid":{"rendered":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/?p=46619"},"modified":"2026-10-11T05:17:41","modified_gmt":"2026-10-11T05:17:41","slug":"wordpress-maintenance-mode-without-plugin","status":"publish","type":"post","link":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wordpress-maintenance-mode-without-plugin\/","title":{"rendered":"Simple WordPress Maintenance Mode Without a Plugin"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">You need WordPress maintenance mode without a plugin: visitors should see a short &#8220;back soon&#8221; page while you work, and you, logged in as an administrator, should keep seeing the real site. This snippet does that with a proper <code>503 Service Unavailable<\/code> status, so search engines treat the downtime as temporary instead of indexing the maintenance message.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The snippet<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php\n\/**\n * Maintenance mode: visitors get a 503 page, administrators see the site.\n *\/\nadd_action( 'template_redirect', 'dpc_maintenance_mode', 1 );\n\nfunction dpc_maintenance_mode(): void {\n\tif ( current_user_can( 'manage_options' ) ) {\n\t\treturn;\n\t}\n\n\tif ( ! headers_sent() ) {\n\t\theader( 'Retry-After: 3600' );\n\t}\n\n\twp_die(\n\t\t'&lt;h1&gt;' . esc_html__( 'Maintenance', 'dpc' ) . '&lt;\/h1&gt;&lt;p&gt;' . esc_html__( 'This site is under scheduled maintenance. Please check back later.', 'dpc' ) . '&lt;\/p&gt;',\n\t\tesc_html__( 'Maintenance', 'dpc' ),\n\t\tarray( 'response' =&gt; 503 )\n\t);\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">How it works<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>template_redirect<\/code> fires on every front-end request just before WordPress picks a template, in classic and block themes alike. The older One-Click Import version hooked into <code>get_header<\/code>, which block themes never call, so their sites stayed public.<\/li>\n\n\n<li><code>current_user_can( 'manage_options' )<\/code> lets administrators through. It returns <code>false<\/code> for logged-out visitors, so no separate login check is needed.<\/li>\n\n\n<li><code>wp_die()<\/code> with <code>'response' =&gt; 503<\/code> sends the status code and no-cache headers. The <code>Retry-After<\/code> header tells crawlers to come back in an hour; it is only sent when headers are still open, so it never raises a warning.<\/li>\n\n\n<li>The message is escaped and translatable, and the status is an integer, as <code>wp_die()<\/code> expects.<\/li>\n\n\n<li>wp-admin, wp-login.php, the REST API, admin-ajax and WP-Cron never fire <code>template_redirect<\/code>, so you can still log in and scheduled tasks keep running.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Add it with Scripts Organizer<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In <a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/dplugins.com\/downloads\/scripts-organizer\/\">Scripts Organizer<\/a> go to <strong>Code Blocks \u2192 Add New<\/strong> and give the block a name. Set <strong>Trigger location<\/strong> to <strong>Everywhere<\/strong>, tick <strong>PHP<\/strong> under <strong>Script location<\/strong>, paste the code into the PHP editor and publish. Leave <strong>Action\/Hook<\/strong> empty. The function is attached to <code>template_redirect<\/code> and only runs there, when WordPress already knows who is logged in. To end maintenance, disable the code block; there is nothing to clean up.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The same code also works unchanged in a small plugin or an mu-plugin.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Customise it<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Let editors in too: change the capability to <code>edit_posts<\/code>.<\/li>\n\n\n<li>Longer work: raise <code>3600<\/code> (seconds) in the <code>Retry-After<\/code> header.<\/li>\n\n\n<li>Keep one page public, such as a contact page: add <code>if ( is_page( 'contact' ) ) { return; }<\/code> after the capability check.<\/li>\n\n\n<li>Own design: replace the <code>wp_die()<\/code> call with <code>status_header( 503 );<\/code>, <code>nocache_headers();<\/code>, your own markup and <code>exit;<\/code>.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">To also keep wp-admin closed to everyone but you while you work, combine it with <a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/lockdown-admin-backend-to-your-ip\/\">Lockdown Admin Backend to your IP<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Gotchas<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Page caches: a caching plugin or host cache may keep serving cached pages to visitors. Purge the cache after you enable the code block, and again after you disable it.<\/li>\n\n\n<li>Keep it short. A 503 is fine for hours; weeks of 503 responses can still cost you indexed pages, and then a real maintenance plugin with a scheduled end is the better tool.<\/li>\n\n\n<li>Logged-in users without <code>manage_options<\/code> (customers, subscribers) see the maintenance page too. That is intended.<\/li>\n\n\n<li>WordPress&#8217;s own <code>.maintenance<\/code> file, written during core updates, is a separate mechanism and is not affected.<\/li>\n\n<\/ul>\n\n","protected":false},"excerpt":{"rendered":"<p>Put WordPress into maintenance mode without a plugin: visitors get a 503 page with Retry-After, administrators keep using the site.<\/p>\n","protected":false},"author":1,"featured_media":46906,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"Simple WordPress Maintenance Mode Without a Plugin","description":"Put WordPress into maintenance mode without a plugin: visitors get a 503 page with Retry-After, administrators keep using the site."},"_slim_seo_primary_term_category":0,"_slim_seo_primary_term_post_tag":0,"footnotes":""},"categories":[131,3],"tags":[168,167,166,169],"dpc_library":[204],"class_list":["post-46619","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-production","category-wordpress","tag-168","tag-maintenance","tag-scripts-organizer","tag-template_redirect"],"_links":{"self":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/46619","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/comments?post=46619"}],"version-history":[{"count":1,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/46619\/revisions"}],"predecessor-version":[{"id":46670,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/46619\/revisions\/46670"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media\/46906"}],"wp:attachment":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media?parent=46619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/categories?post=46619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/tags?post=46619"},{"taxonomy":"dpc_library","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/dpc_library?post=46619"}],"curies":[{"name":"wp","href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/api.w.org\/{rel}","templated":true}]}}