Title

PHP WP-Admin dashboard styling CSS

description

Add CSS to the WP-Admin dashboard backend, for general styling or to hide elements for specific users

Published 2022-08-12

Modified 2022-08-19

content

				
					add_action('admin_head', 'dashboard_css');

function dashboard_css() {
    $user = get_current_user_id();
    $infoadmin = '3';
    $nogiemand = '456';
      if( $user == $infoadmin || $user == $nogiemand ) {
        echo '<style>
                /* ADMIN LEFT MAIN MENU */
                    /* pages */
                        li#menu-pages .wp-submenu,
                    /*edit home page */
                        div.editor-styles-wrapper.block-editor-writing-flow, 
                    /*media*/
                        li#menu-media,
                    /* comments */
                        li#menu-comments,
                    /* elementor */
                        li#toplevel_page_elementor,
                    /* templates */
                        li#menu-posts-elementor_library,
                    /* crocoblock */
                        li#toplevel_page_jet-dashboard,
                    /* appearance */
                        li#menu-appearance,
                    /* plugins */
                        li#menu-plugins,
                    /* snippets */
                        li#toplevel_page_snippets,
                    /* users */
                        li#menu-users,
                    /* tools */
                        li#menu-tools,
                    /* settings */
                        li#menu-settings,
                    /* acf */
                        li#toplevel_page_edit-post_type-acf-field-group,
                    /* smart filters */
                        li#menu-posts-jet-smart-filters,
                /* ADMIN TOP BAR */
                    li#wp-admin-bar-wp-logo, li#wp-admin-bar-site-name .ab-sub-wrapper, li#wp-admin-bar-customize, li#wp-admin-bar-comments, li#wp-admin-bar-new-content, 
                    li#wp-admin-bar-elementor_edit_page,li#wp-admin-bar-wpseo-menu, li#wp-admin-bar-warpdrive_top_menu, li#wp-admin-bar-elementor-maintenance-on,
                /* NOTICES */
                    .notice-info,
                /* EDIT PAGE WITH ELEMENTOR */
                    #post-body-content #elementor-switch-mode, #post-body-content #elementor-editor,
                {display:none!important;}
            </style>';
      }
}
				
			

Sources & References