{"id":45985,"date":"2022-11-28T11:00:02","date_gmt":"2022-11-28T11:00:02","guid":{"rendered":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/?p=45985"},"modified":"2026-10-11T05:16:49","modified_gmt":"2026-10-11T05:16:49","slug":"custom-dashboard","status":"publish","type":"post","link":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/custom-dashboard\/","title":{"rendered":"Replace the WordPress Dashboard With a Custom Page"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The default WordPress dashboard is full of widgets your clients do not need. A page you design yourself, with links to the screens they use, short instructions and your contact details, is much more useful.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This snippet replaces the WordPress dashboard with any page of your site. Build the page in the block editor, Bricks, Oxygen, Elementor or another builder, put its URL in the config, and it fills the dashboard area next to the admin menu.<\/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 * Replace the WordPress dashboard with a page built in the block editor or a page builder.\n *\/\n\n\/\/ ===== Config =====\nfunction dpc_custom_dashboard_config() {\n\t$config = array(\n\t\t\/\/ The page shown as the dashboard. A page on this site works best.\n\t\t'url'         =&gt; home_url( '\/dashboard\/' ),\n\t\t\/\/ true = administrators keep the normal dashboard, everyone else gets the page.\n\t\t'skip_admins' =&gt; false,\n\t);\n\t\/\/ ===== End of config =====\n\n\treturn (array) apply_filters( 'dpc_custom_dashboard_config', $config );\n}\n\n\/** Whether the current user gets the custom dashboard. *\/\nfunction dpc_custom_dashboard_applies() {\n\t$config = dpc_custom_dashboard_config();\n\n\tif ( '' === (string) ( $config&#91;'url'&#93; ?? '' ) ) {\n\t\treturn false;\n\t}\n\n\treturn ! ( ! empty( $config&#91;'skip_admins'&#93; ) &amp;&amp; current_user_can( 'manage_options' ) );\n}\n\n\/\/ 1. Remove every dashboard widget and the Welcome panel.\nadd_action( 'wp_dashboard_setup', 'dpc_custom_dashboard_remove_widgets', PHP_INT_MAX );\n\nfunction dpc_custom_dashboard_remove_widgets() {\n\tglobal $wp_meta_boxes;\n\n\tif ( ! dpc_custom_dashboard_applies() ) {\n\t\treturn;\n\t}\n\n\tforeach ( (array) ( $wp_meta_boxes&#91;'dashboard'&#93; ?? array() ) as $context =&gt; $priorities ) {\n\t\tforeach ( (array) $priorities as $widgets ) {\n\t\t\tforeach ( array_keys( (array) $widgets ) as $widget_id ) {\n\t\t\t\tremove_meta_box( $widget_id, 'dashboard', $context );\n\t\t\t}\n\t\t}\n\t}\n\n\tremove_action( 'welcome_panel', 'wp_welcome_panel' );\n}\n\n\/\/ 2. CSS that places the frame next to the admin menu and below the toolbar.\nadd_action( 'admin_enqueue_scripts', 'dpc_custom_dashboard_style' );\n\nfunction dpc_custom_dashboard_style( $hook_suffix ) {\n\tif ( 'index.php' !== $hook_suffix || ! dpc_custom_dashboard_applies() ) {\n\t\treturn;\n\t}\n\n\t$css = '#dpc-custom-dashboard{position:fixed;top:32px;left:160px;z-index:9989;width:calc(100% - 160px);height:calc(100% - 32px);border:0;background:#fff}'\n\t\t. '.folded #dpc-custom-dashboard{left:36px;width:calc(100% - 36px)}'\n\t\t. '@media (max-width:960px){.auto-fold #dpc-custom-dashboard{left:36px;width:calc(100% - 36px)}}'\n\t\t. '@media (max-width:782px){.auto-fold #dpc-custom-dashboard{top:46px;left:0;width:100%;height:calc(100% - 46px)}}';\n\n\twp_register_style( 'dpc-custom-dashboard', false, array(), null );\n\twp_add_inline_style( 'dpc-custom-dashboard', $css );\n\twp_enqueue_style( 'dpc-custom-dashboard' );\n}\n\n\/\/ 3. The frame itself, inside the admin page markup.\nadd_action( 'admin_footer', 'dpc_custom_dashboard_frame' );\n\nfunction dpc_custom_dashboard_frame() {\n\t$screen = get_current_screen();\n\tif ( ! $screen || 'dashboard' !== $screen-&gt;id || ! dpc_custom_dashboard_applies() ) {\n\t\treturn;\n\t}\n\n\t$config = dpc_custom_dashboard_config();\n\n\tprintf(\n\t\t'&lt;iframe id=\"dpc-custom-dashboard\" src=\"%1$s\" title=\"%2$s\"&gt;&lt;\/iframe&gt;',\n\t\tesc_url( add_query_arg( 'dpc_dashboard', '1', $config&#91;'url'&#93; ) ),\n\t\tesc_attr__( 'Dashboard', 'dpc' )\n\t);\n}\n\n\/\/ 4. Inside the frame: no second toolbar, and links open in the full window.\nadd_filter( 'show_admin_bar', 'dpc_custom_dashboard_admin_bar' );\n\nfunction dpc_custom_dashboard_admin_bar( $show ) {\n\treturn dpc_custom_dashboard_is_frame() ? false : $show;\n}\n\nadd_action( 'wp_head', 'dpc_custom_dashboard_base_target', 1 );\n\nfunction dpc_custom_dashboard_base_target() {\n\tif ( dpc_custom_dashboard_is_frame() ) {\n\t\techo '&lt;base target=\"_top\"&gt;' . \"\\n\";\n\t}\n}\n\nfunction dpc_custom_dashboard_is_frame() {\n\t\/\/ Only switches the toolbar off and changes the link target, so no nonce is needed.\n\t\/\/ phpcs:ignore WordPress.Security.NonceVerification.Recommended\n\treturn isset( $_GET&#91;'dpc_dashboard'&#93; ) &amp;&amp; '1' === $_GET&#91;'dpc_dashboard'&#93;;\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>Everywhere<\/strong>, tick <strong>PHP<\/strong> under <strong>Script location<\/strong>, paste the code into the PHP editor, set the <code>url<\/code> in the config and publish. Leave <strong>Action\/Hook<\/strong> empty.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Everywhere<\/strong> is needed for step 4: the page inside the frame is a front-end request, and that is where the admin bar is hidden. The dashboard parts only run on dashboard hooks, so the front end otherwise does nothing. The CSS is printed from PHP, so no separate header code is needed.<\/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\">How it works<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>wp_dashboard_setup<\/code> runs after every plugin has added its widgets. At the latest priority the snippet removes all of them, in every column and priority, and switches off the Welcome panel. The <code>foreach<\/code> loops cast to arrays, so empty columns no longer cause PHP 8 warnings.<\/li>\n\n\n<li>The frame is printed on <code>admin_footer<\/code>, inside the admin page. The earlier version echoed it on <code>wp_dashboard_setup<\/code>, which runs before WordPress prints <code>&lt;html&gt;<\/code>, so the markup landed at the very top of the document.<\/li>\n\n\n<li>The CSS places the frame below the toolbar and next to the admin menu, and follows the folded menu and the mobile layout. It is only added on the dashboard screen.<\/li>\n\n\n<li>The frame URL gets <code>?dpc_dashboard=1<\/code>. With that parameter the front end hides its admin bar and adds <code>&lt;base target=\"_top\"&gt;<\/code>, so links in your page open in the whole window instead of inside the frame.<\/li>\n\n\n<li>The URL is escaped with <code>esc_url()<\/code>, and <code>skip_admins<\/code> lets administrators keep the normal dashboard.<\/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>Clients only: set <code>'skip_admins' =&gt; true<\/code>.<\/li>\n\n\n<li>A page that should not be public: make it private in WordPress. Logged-in editors and admins can still open it inside the frame.<\/li>\n\n\n<li>Different pages per role: return a different <code>url<\/code> from the <code>dpc_custom_dashboard_config<\/code> filter based on <code>current_user_can()<\/code>.<\/li>\n\n\n<li>Prefer fields over a page builder? See <a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/custom-dashboard-with-metabox\/\">Custom Dashboard with Metabox<\/a>.<\/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>Pages on another domain usually refuse to be framed (<code>X-Frame-Options<\/code> or <code>frame-ancestors<\/code>), and you get an empty frame. Use a page on the same site.<\/li>\n\n\n<li>Removing every widget also removes the PHP and browser update nags and Site Health. Keep an eye on <strong>Tools \u2192 Site Health<\/strong> yourself.<\/li>\n\n\n<li>Pages you navigate to inside the frame without the parameter show the admin bar again. With the base target links leave the frame, so this rarely happens.<\/li>\n\n\n<li>The page is a normal front-end page: caching plugins may cache it. Exclude it from the page cache if it shows user-specific content.<\/li>\n\n<\/ul>\n\n","protected":false},"excerpt":{"rendered":"<p>Replace the WordPress admin dashboard with a page you built in Gutenberg, Bricks, Oxygen or Elementor, shown full width next to the admin menu.<\/p>\n","protected":false},"author":1,"featured_media":46902,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"Replace the WordPress Dashboard With a Custom Page","description":"Replace the WordPress admin dashboard with a page you built in Gutenberg, Bricks, Oxygen or Elementor, shown full width next to the admin menu."},"_slim_seo_primary_term_category":0,"_slim_seo_primary_term_post_tag":0,"footnotes":""},"categories":[3],"tags":[89,88,6],"dpc_library":[204],"class_list":["post-45985","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","tag-custom","tag-dashboard","tag-wp-admin"],"_links":{"self":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/45985","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=45985"}],"version-history":[{"count":1,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/45985\/revisions"}],"predecessor-version":[{"id":46753,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/45985\/revisions\/46753"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media\/46902"}],"wp:attachment":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media?parent=45985"}],"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=45985"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/tags?post=45985"},{"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=45985"}],"curies":[{"name":"wp","href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/api.w.org\/{rel}","templated":true}]}}