{"id":14129,"date":"2021-05-09T18:51:45","date_gmt":"2021-05-09T18:51:45","guid":{"rendered":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/dplugins.com\/?post_type=code_snippets&#038;p=14129"},"modified":"2026-10-10T19:54:15","modified_gmt":"2026-10-10T19:54:15","slug":"wordpress-admin-dark-theme","status":"publish","type":"post","link":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wordpress-admin-dark-theme\/","title":{"rendered":"WordPress Admin Dark Theme"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">WordPress has no dark mode for wp-admin. The admin colour schemes under your profile only change the sidebar, and the content stays a large white screen. Dark mode plugins exist, but many load a lot of CSS and JavaScript for what is mostly a colour change.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This WordPress admin dark theme is a few lines of CSS. It inverts the admin screens and the block editor&#8217;s toolbar and sidebars, turns images and colour swatches back to their real colours, and leaves the editor canvas in your theme&#8217;s colours, so you still see the post as visitors will.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The CSS<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"css\" class=\"language-css\">\/* WordPress admin dark theme (dpc). CSS only, loaded in wp-admin. *\/\n\n\/* Dark page behind the inverted content. *\/\nbody.wp-admin,\n.wp-admin #wpwrap {\n\tbackground-color: #1d1d1d;\n}\n\n\/* Classic screens: invert the content area, turn the hues back so links stay blue. *\/\n.wp-admin:not(.block-editor-page) #wpbody {\n\tfilter: invert(0.9) hue-rotate(180deg);\n}\n\n\/* Block editor: invert the toolbar and the sidebars; the canvas keeps the theme's own colours. *\/\n.block-editor-page :is(.interface-interface-skeleton__header, .interface-interface-skeleton__sidebar, .interface-interface-skeleton__secondary-sidebar, .interface-interface-skeleton__footer) {\n\tfilter: invert(0.9) hue-rotate(180deg);\n}\n\n.block-editor-page .interface-interface-skeleton__content {\n\tbackground-color: #1d1d1d;\n}\n\n\/* Show images, video, embeds and colour swatches in their real colours again. *\/\n.wp-admin:not(.block-editor-page) #wpbody :is(img, video, iframe, .wp-color-result, .iris-picker),\n.block-editor-page :is(.interface-interface-skeleton__header, .interface-interface-skeleton__sidebar, .interface-interface-skeleton__secondary-sidebar) :is(img, video, iframe, .components-color-palette__custom-color-button, .components-circular-option-picker__option) {\n\tfilter: invert(1) hue-rotate(180deg);\n}<\/code><\/pre>\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>Admin only<\/strong>, tick <strong>Header<\/strong> under <strong>Script location<\/strong>, set <strong>Header Mode<\/strong> to <strong>CSS<\/strong>, paste the CSS and publish.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With <strong>Admin only<\/strong> the CSS is printed in the <code>&lt;head&gt;<\/code> of every wp-admin page, for every logged-in user who opens wp-admin, and never on the front end. No PHP is needed. The older version of this post echoed the same kind of CSS from a PHP function on <code>admin_head<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Without Scripts Organizer, load the CSS with <code>wp_add_inline_style()<\/code> on <code>admin_enqueue_scripts<\/code> in a small plugin.<\/p>\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>filter: invert(0.9)<\/code> turns white into dark grey and black text into light grey. <code>hue-rotate(180deg)<\/code> turns the inverted colours back around the colour wheel, so blue links and buttons stay blue instead of orange.<\/li>\n\n\n<li>The admin menu and the admin bar are already dark, so only <code>#wpbody<\/code>, the content area, is inverted.<\/li>\n\n\n<li>Images, video, iframes and colour swatches are inverted a second time with <code>invert(1) hue-rotate(180deg)<\/code>, which brings them close to their real colours.<\/li>\n\n\n<li>In the block editor the post content is inside an iframe. Inverting it would turn your photos and colours into negatives, so only the editor&#8217;s toolbar, sidebars and footer are inverted. The older version targeted <code>.editor-styles-wrapper<\/code>, which no longer exists outside that iframe, so the editor was left half white.<\/li>\n\n\n<li><code>#wpbody<\/code> is not filtered on block editor screens. A <code>filter<\/code> makes an element the reference for <code>position: fixed<\/code> children, and the full-screen editor is one of those.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Customise it<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Softer or harder contrast: change <code>0.9<\/code> in both <code>invert(0.9)<\/code> rules, for example to <code>0.85<\/code> (the original value) or <code>1<\/code>.<\/li>\n\n\n<li>Only for you: the Admin only trigger has no user condition, so if other users should keep the light admin, wrap the CSS in PHP and print it only for your user ID.<\/li>\n\n\n<li>Something still looks wrong, such as a plugin&#8217;s chart: add its selector to the last rule so it is turned back.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Gotchas<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It is a filter trick, not a designed dark theme. Shadows look like light glows, and some plugin screens with their own colours look odd.<\/li>\n\n\n<li>Popovers and dropdowns in the block editor, the media modal and the Site Editor are not inverted and stay light.<\/li>\n\n\n<li>Inverting large areas costs some rendering time on very long list tables. On a slow machine you may notice it while scrolling.<\/li>\n\n\n<li>Prefer colour-coding the admin menu instead? See <a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/color-admin-menu-items\/\">Color Admin Menu Items<\/a>.<\/li>\n\n<\/ul>\n\n","protected":false},"excerpt":{"rendered":"<p>A WordPress admin dark theme in a few lines of CSS: dark wp-admin screens and block editor UI, real colours for images and the editor canvas.<\/p>\n","protected":false},"author":1,"featured_media":46713,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"WordPress Admin Dark Theme - Code DPlugins","description":"A WordPress admin dark theme in a few lines of CSS: dark wp-admin screens and block editor UI, real colours for images and the editor canvas."},"_slim_seo_primary_term_category":0,"_slim_seo_primary_term_post_tag":0,"footnotes":""},"categories":[3],"tags":[],"dpc_library":[204],"class_list":["post-14129","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress"],"_links":{"self":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/14129","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=14129"}],"version-history":[{"count":1,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/14129\/revisions"}],"predecessor-version":[{"id":46712,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/14129\/revisions\/46712"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media\/46713"}],"wp:attachment":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media?parent=14129"}],"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=14129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/tags?post=14129"},{"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=14129"}],"curies":[{"name":"wp","href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/api.w.org\/{rel}","templated":true}]}}