The Easiest Way to Hide Menu Items from the WordPress Admin Sidebar

Last updated on Jun 9, 2026

After installing a new plugin on your WordPress website, you will typically see a new menu item on the sidebar inside your dashboard. Not all plugins add a new menu item but most of them do. Especially commercial plugins.

The more plugins you install, the more cluttered your admin sidebar will be.

Is there a way to hide a certain menu item from the admin sidebar without interrupting the functionality of the plugin correlated to it?

That's what I want to cover in this post. So, read on.

In this post, I will show you how to hide menu items from your WordPress admin sidebar without using a plugin.

Shortcuts ⤵️

Hiding Menu Items from the WordPress Admin Sidebar without a Plugin

Some time ago, I stumbled on a YouTube video covering how to hide menu items from the WordPress admin sidebar. The video got me interested because it showed the no-plugin method.

Instead, it showed how to hide the menu items from the admin sidebar using a custom function.

The YouTuber even provided the code snippet although you needed to install the Code Snippets plugin because it was (the snippet) available in a JSON file, being exported from Code Snippets.

After importing the JSON file to Code Snippets on my playground environment, I copied the code snippet and added it to my custom plugin and it worked. So, I wanted to share it here with you.

If you prefer to use a plugin to hide menu items from your admin sidebar, you can use Admin Menu Editor.

What Does the Custom Function Do?

I really love the method that the custom function offers to hide menu items from WordPress admin sidebar because it is super clean and flexible.

After you add the custom function, you will see a new screen element on your WordPress dashboard that enlists the menu items on your admin sidebar.

Each item on the list has a checkbox where if it is checked, the associated menu item will be shown. If you want to hide a certain menu item, you can simply uncheck it.

As simple as that.

Hide menu items from WordPress admin sidebar with custom function

The best part, you can also disable the screen element like other screen elements.

The custom function itself recognizes all menu items on the admin sidebar. Be it the built-in menu items of WordPress or menu items added by plugins.

Adding the Custom Function

As I said above, the code snippet of the custom function is available in a JSON file which you need to import to your website via Code Snippets plugin. You can get the JSON file here.

After importing the JSON file, you will get the PHP code snippet of the custom function.

If you don't want to bother importing the JSON file, I have provided the PHP snippet below which you can copy directly.

Show code snippet
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! class_exists( 'WSQ_WP_Sidebar_Toggle_Hardened' ) ) {

	class WSQ_WP_Sidebar_Toggle_Hardened {

		private $meta_key     = 'wsq_wp_sidebar_hidden_items';
		private $ajax_action  = 'wsq_save_wp_sidebar_toggle';
		private $reset_action = 'wsq_reset_wp_sidebar_toggle';
		private $nonce_action = 'wsq_wp_sidebar_toggle_nonce';

		public function __construct() {
			add_action( 'wp_dashboard_setup', [ $this, 'add_dashboard_widget' ] );
			add_action( 'admin_head', [ $this, 'print_admin_css' ] );
			add_action( 'admin_footer', [ $this, 'print_admin_script' ] );
			add_action( 'wp_ajax_' . $this->ajax_action, [ $this, 'ajax_save_options' ] );
			add_action( 'wp_ajax_' . $this->reset_action, [ $this, 'ajax_reset_options' ] );
		}

		public function add_dashboard_widget() {
			if ( ! current_user_can( 'read' ) ) {
				return;
			}

			wp_add_dashboard_widget(
				'wsq_wp_sidebar_toggle_widget',
				'WP Sidebar',
				[ $this, 'render_dashboard_widget' ]
			);
		}

		public function render_dashboard_widget() {
			if ( ! current_user_can( 'read' ) ) {
				echo '<p>You do not have permission to use this.</p>';
				return;
			}

			echo '<div id="wsq-wp-sidebar-toggle-container"></div>';
			echo '<p id="wsq-wp-sidebar-toggle-loading" style="color:#666;font-style:italic;">Loading sidebar items...</p>';

			echo '<p style="margin-top:12px;color:#666;">Untick an item to hide it from your admin sidebar. Tick it again to restore it.</p>';

			echo '<p style="margin-top:14px;">';
			echo '<button type="button" class="button" id="wsq-wp-sidebar-toggle-reset">Reset all sidebar items</button>';
			echo '</p>';

			echo '<p id="wsq-wp-sidebar-toggle-message" style="display:none;margin-top:10px;"></p>';
		}

			public function print_admin_css() {
				if ( ! is_admin() || ! current_user_can( 'read' ) ) {
					return;
				}
				?>
				<style>
					#adminmenu > li.wsq-sidebar-hidden-item {
						display: none !important;
					}

					/* Fix the gaps */
					#adminmenu > li.wp-menu-separator {
						display: none !important;
					}

					#wsq-wp-sidebar-toggle-container label {
						cursor: pointer;
					}

					#wsq-wp-sidebar-toggle-container input[type="checkbox"] {
						margin-right: 6px;
					}

					.wsq-sidebar-toggle-row {
						margin-bottom: 8px;
					}
				</style>
				<?php
			}

		public function print_admin_script() {
			if ( ! is_admin() || ! current_user_can( 'read' ) ) {
				return;
			}

			$screen       = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
			$is_dashboard = ( $screen && 'dashboard' === $screen->id );

			$hidden_items = get_user_meta( get_current_user_id(), $this->meta_key, true );

			if ( ! is_array( $hidden_items ) ) {
				$hidden_items = [];
			}

			$data = [
				'ajaxUrl'      => admin_url( 'admin-ajax.php' ),
				'nonce'        => wp_create_nonce( $this->nonce_action ),
				'hiddenItems'  => array_values( array_map( 'strval', $hidden_items ) ),
				'isDashboard'  => (bool) $is_dashboard,
				'saveAction'   => $this->ajax_action,
				'resetAction'  => $this->reset_action,
			];
			?>
			<script>
			(function() {
				'use strict';

				const wsqSidebarData = <?php echo wp_json_encode( $data ); ?>;

				let checklistBuilt = false;
				let observerStarted = false;
				let rebuildTimer = null;

				document.addEventListener('DOMContentLoaded', function() {
					applySavedHiddenItems();
					startMenuObserver();

					if (wsqSidebarData.isDashboard) {
						setTimeout(function() {
							buildChecklist();
							attachResetButton();
						}, 250);
					}
				});

				function normalizeSlug(href) {
					if (!href) return '';

					let slug = String(href).trim();

					try {
						const fakeBase = window.location.origin + window.location.pathname;
						const url = new URL(slug, fakeBase);

						const page = url.searchParams.get('page');
						if (page) {
							return page.trim();
						}

						const postType = url.searchParams.get('post_type');
						const taxonomy = url.searchParams.get('taxonomy');

						if (slug.indexOf('edit.php') !== -1 && postType) {
							return 'edit.php?post_type=' + postType;
						}

						if (slug.indexOf('edit-tags.php') !== -1 && taxonomy) {
							return 'edit-tags.php?taxonomy=' + taxonomy;
						}

						let path = url.pathname.split('/').pop();

						if (!path || path === 'admin.php') {
							path = slug;
						}

						if (url.search && !page) {
							const cleanSearch = url.search.replace(/^\?/, '');
							return path + '?' + cleanSearch;
						}

						return path || slug;
					} catch (e) {
						if (slug.indexOf('admin.php?page=') === 0) {
							return slug.replace('admin.php?page=', '').trim();
						}

						return slug;
					}
				}

				function getTopLevelMenuItems() {
					return Array.from(document.querySelectorAll('#adminmenu > li.menu-top'));
				}

				function getMenuItemData(li) {
					if (!li) return null;

					if (li.classList.contains('wp-menu-separator')) return null;
					if (li.id === 'collapse-menu') return null;

					const link = li.querySelector('a.menu-top');
					if (!link) return null;

					const href = link.getAttribute('href');
					if (!href || href === '#') return null;

					const slug = normalizeSlug(href);
					if (!slug) return null;

					const nameEl = link.querySelector('.wp-menu-name');
					if (!nameEl) return null;

					const temp = document.createElement('div');
					temp.innerHTML = nameEl.innerHTML;

					temp.querySelectorAll('span, .update-plugins, .awaiting-mod, .plugin-count, .theme-count').forEach(function(node) {
						node.remove();
					});

					const title = (temp.textContent || '').trim();
					if (!title) return null;

					return {
						li: li,
						link: link,
						href: href,
						slug: slug,
						title: title
					};
				}

				function hideMenuItem(li) {
					if (!li) return;

					li.classList.add('wsq-sidebar-hidden-item');
					li.setAttribute('data-wsq-sidebar-hidden', '1');
				}

				function showMenuItem(li) {
					if (!li) return;

					li.classList.remove('wsq-sidebar-hidden-item');
					li.removeAttribute('data-wsq-sidebar-hidden');

					if (li.style && li.style.display === 'none') {
						li.style.display = '';
					}
				}

				function applySavedHiddenItems() {
					const hidden = Array.isArray(wsqSidebarData.hiddenItems) ? wsqSidebarData.hiddenItems : [];

					getTopLevelMenuItems().forEach(function(li) {
						const item = getMenuItemData(li);
						if (!item) return;

						if (hidden.includes(item.slug)) {
							hideMenuItem(li);
						} else if (li.classList.contains('wsq-sidebar-hidden-item')) {
							showMenuItem(li);
						}
					});
				}

				function buildChecklist() {
					const container = document.getElementById('wsq-wp-sidebar-toggle-container');
					const loading = document.getElementById('wsq-wp-sidebar-toggle-loading');

					if (!container) return;

					const seenSlugs = new Set();
					const rows = [];

					getTopLevelMenuItems().forEach(function(li) {
						const item = getMenuItemData(li);
						if (!item) return;

						const computed = window.getComputedStyle(li);
						const hiddenByOtherCode = computed.display === 'none' && !li.classList.contains('wsq-sidebar-hidden-item');

						if (hiddenByOtherCode) {
							return;
						}

						if (seenSlugs.has(item.slug)) {
							return;
						}

						seenSlugs.add(item.slug);
						rows.push(item);
					});

					if (!rows.length) {
						container.innerHTML = '<p>No menu items found.</p>';
						if (loading) loading.remove();
						return;
					}

					let html = '';

					rows.forEach(function(item) {
						const checked = !wsqSidebarData.hiddenItems.includes(item.slug) ? 'checked="checked"' : '';
						const safeId = 'wsq-sidebar-toggle-' + item.slug.replace(/[^a-zA-Z0-9\-_:.]/g, '-');

						html += `
							<div class="wsq-sidebar-toggle-row">
								<label for="${safeId}">
									<input
										type="checkbox"
										class="wsq-sidebar-toggle-checkbox"
										id="${safeId}"
										value="${escapeHtmlAttr(item.slug)}"
										${checked}
									/>
									${escapeHtml(item.title)}
								</label>
							</div>
						`;
					});

					container.innerHTML = html;
					attachCheckboxListeners();

					if (loading) {
						loading.remove();
					}

					checklistBuilt = true;
				}

				function attachCheckboxListeners() {
					document.querySelectorAll('.wsq-sidebar-toggle-checkbox').forEach(function(checkbox) {
						checkbox.addEventListener('change', function() {
							const slug = this.value;
							const shouldHide = !this.checked;

							toggleMenuItemBySlug(slug, shouldHide);
							updateLocalHiddenItems(slug, shouldHide);
							savePreference(slug, shouldHide, this);
						});
					});
				}

				function toggleMenuItemBySlug(slug, shouldHide) {
					getTopLevelMenuItems().forEach(function(li) {
						const item = getMenuItemData(li);
						if (!item) return;

						if (item.slug === slug) {
							if (shouldHide) {
								hideMenuItem(li);
							} else {
								showMenuItem(li);
							}
						}
					});
				}

				function updateLocalHiddenItems(slug, isHidden) {
					if (!Array.isArray(wsqSidebarData.hiddenItems)) {
						wsqSidebarData.hiddenItems = [];
					}

					if (isHidden) {
						if (!wsqSidebarData.hiddenItems.includes(slug)) {
							wsqSidebarData.hiddenItems.push(slug);
						}
					} else {
						wsqSidebarData.hiddenItems = wsqSidebarData.hiddenItems.filter(function(item) {
							return item !== slug;
						});
					}
				}

				function savePreference(slug, isHidden, checkbox) {
					const formData = new FormData();

					formData.append('action', wsqSidebarData.saveAction);
					formData.append('nonce', wsqSidebarData.nonce);
					formData.append('slug', slug);
					formData.append('is_hidden', isHidden ? 'true' : 'false');

					fetch(wsqSidebarData.ajaxUrl, {
						method: 'POST',
						body: formData,
						credentials: 'same-origin'
					})
					.then(function(response) {
						return response.json();
					})
					.then(function(data) {
						if (!data || !data.success) {
							throw new Error('Save failed');
						}

						showMessage('Saved.', 'success');
					})
					.catch(function() {
						checkbox.checked = isHidden;
						updateLocalHiddenItems(slug, !isHidden);
						toggleMenuItemBySlug(slug, !isHidden);

						showMessage('Could not save your sidebar preference.', 'error');
					});
				}

				function attachResetButton() {
					const button = document.getElementById('wsq-wp-sidebar-toggle-reset');

					if (!button) return;

					button.addEventListener('click', function() {
						const formData = new FormData();

						formData.append('action', wsqSidebarData.resetAction);
						formData.append('nonce', wsqSidebarData.nonce);

						button.disabled = true;
						button.textContent = 'Resetting...';

						fetch(wsqSidebarData.ajaxUrl, {
							method: 'POST',
							body: formData,
							credentials: 'same-origin'
						})
						.then(function(response) {
							return response.json();
						})
						.then(function(data) {
							if (!data || !data.success) {
								throw new Error('Reset failed');
							}

							wsqSidebarData.hiddenItems = [];

							getTopLevelMenuItems().forEach(function(li) {
								showMenuItem(li);
							});

							document.querySelectorAll('.wsq-sidebar-toggle-checkbox').forEach(function(checkbox) {
								checkbox.checked = true;
							});

							showMessage('All sidebar items restored.', 'success');
						})
						.catch(function() {
							showMessage('Could not reset sidebar items.', 'error');
						})
						.finally(function() {
							button.disabled = false;
							button.textContent = 'Reset all sidebar items';
						});
					});
				}

				function startMenuObserver() {
					if (observerStarted) return;

					const adminMenu = document.getElementById('adminmenu');
					if (!adminMenu || typeof MutationObserver === 'undefined') return;

					const observer = new MutationObserver(function() {
						clearTimeout(rebuildTimer);

						rebuildTimer = setTimeout(function() {
							applySavedHiddenItems();

							if (wsqSidebarData.isDashboard && checklistBuilt) {
								buildChecklist();
							}
						}, 250);
					});

					observer.observe(adminMenu, {
						childList: true,
						subtree: true,
						attributes: true,
						attributeFilter: ['class', 'style']
					});

					observerStarted = true;
				}

				function showMessage(message, type) {
					const messageEl = document.getElementById('wsq-wp-sidebar-toggle-message');

					if (!messageEl) return;

					messageEl.style.display = 'block';
					messageEl.textContent = message;
					messageEl.style.color = type === 'error' ? '#b32d2e' : '#2271b1';

					clearTimeout(messageEl._wsqTimer);

					messageEl._wsqTimer = setTimeout(function() {
						messageEl.style.display = 'none';
					}, 2500);
				}

				function escapeHtml(str) {
					return String(str)
						.replace(/&/g, '&amp;')
						.replace(/</g, '&lt;')
						.replace(/>/g, '&gt;')
						.replace(/"/g, '&quot;')
						.replace(/'/g, '&#039;');
				}

				function escapeHtmlAttr(str) {
					return escapeHtml(str);
				}

			})();
			</script>
			<?php
		}

		public function ajax_save_options() {
			if ( ! current_user_can( 'read' ) ) {
				wp_send_json_error( [ 'message' => 'Permission denied.' ], 403 );
			}

			check_ajax_referer( $this->nonce_action, 'nonce' );

			$slug      = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
			$is_hidden = isset( $_POST['is_hidden'] ) && 'true' === sanitize_text_field( wp_unslash( $_POST['is_hidden'] ) );

			if ( '' === $slug ) {
				wp_send_json_error( [ 'message' => 'No slug provided.' ], 400 );
			}

			$hidden_items = get_user_meta( get_current_user_id(), $this->meta_key, true );

			if ( ! is_array( $hidden_items ) ) {
				$hidden_items = [];
			}

			$hidden_items = array_values( array_unique( array_map( 'strval', $hidden_items ) ) );

			if ( $is_hidden ) {
				if ( ! in_array( $slug, $hidden_items, true ) ) {
					$hidden_items[] = $slug;
				}
			} else {
				$hidden_items = array_values(
					array_filter(
						$hidden_items,
						function( $item ) use ( $slug ) {
							return $item !== $slug;
						}
					)
				);
			}

			update_user_meta( get_current_user_id(), $this->meta_key, $hidden_items );

			wp_send_json_success(
				[
					'hidden_items' => $hidden_items,
				]
			);
		}

		public function ajax_reset_options() {
			if ( ! current_user_can( 'read' ) ) {
				wp_send_json_error( [ 'message' => 'Permission denied.' ], 403 );
			}

			check_ajax_referer( $this->nonce_action, 'nonce' );

			delete_user_meta( get_current_user_id(), $this->meta_key );

			wp_send_json_success(
				[
					'hidden_items' => [],
				]
			);
		}
	}

	new WSQ_WP_Sidebar_Toggle_Hardened();
}

You can add the code snippet to your website by editing the functions.php file of your theme, using a code snippet management plugin (Code Snippets, FluentSnippets, etc) or by creating a custom plugin, which I personally more recommend.

For detailed instructions, you can read our post about how to add a custom function in WordPress.

Using the Custom Function to Hide the Menu Items from WordPress Admin Sidebar

After adding the code snippet, you will see a new screen element on your WordPress dashboard called WP Sidebar.

If you expand this element, you will be presented with a list of the menu items on your admin sidebar.

Menu items list on WordPress admin sidebar

By default, all menu items are checked. Meaning that they are shown on the admin sidebar. If you want to hide a certain menu item, you can uncheck it and it will be hidden instantly.

Hiding LinkCentral menu item

To re-show the menu item you have hidden, you can simply re-check it and it will be visible again on the admin sidebar.

If you want to make your WordPress dashboard even cleaner, you can disable the screen element of WP Sidebar.

To do so, Click Screen Options on the upper-right corner and uncheck WP Sidebar. This will hide WP Sidebar from your WordPress dashboard.

You can simply re-check it if you want to show it on your WordPress dashboard again.

WordPress screen options

Pro Tip

As I said in the opening section, most WordPress plugins add a new menu item to the admin sidebar after you install and activate them.

The menu item is aimed at making it easy for you to access the plugin screens.

The problem is, not all plugin screens need to be visited regularly. ACF, for instance.

Once you are done creating a custom post type and custom fields, I am convinced that you rarely go to the ACF screen unless you want to make changes to the settings. And you don't do this every single day. Don't you?

So, it totally makes sense to temporarily hide the plugin menu items from the admin sidebar and show it again when you want to access the plugin screen.

If you are building a website for a client, this practice will be super helpful for you to deliver a website with a clean dashboard.

Also, don't forget that WordPress now has a Command Palette feature which can function as a shortcut to jump between screens on the dashboard. You can access it by pressing the command+K keys on Mac and Ctrl+K on Windows and Linux.

Summary

You can install as many plugins as you like on your WordPress dashboard. However, you need to be aware that installing a new plugin means a new menu item will be added to your admin sidebar.

The more plugins you install, the more cluttered your admin sidebar will be.

If you build a website for a client, leaving your admin sidebar polluted with menu items is not a good practice. You can hide the unnecessary menu items and show only the necessary ones. This way, your client will have a good impression on WordPress as the platform and you as the developer.

If you manage your own website, hiding unnecessary menu items is good for productivity because cluttered a dashboard can lead to a bad mood.

This page may contain affiliate links, which help support the project. Read our affiliate disclosure.

Aliko Sunawang

Aliko is a professional blogger and web creator. He has been blogging with WordPress since 2013. In his spare time, he loves going out to take some photos. More

suggested posts

Cloudways vs SiteGround

Cloudways vs SiteGround

I used to use SiteGround and already moved all of my websites to Cloudways because SiteGround is getting…

Migrating a WordPress site to Cloudways

How to Migrate Your WordPress Site to a New Hosting without Downtime

If your website is growing bigger, maybe it is the time to move it to a more reliable hosting service. And...

Struggling to grow your website?

Learn the art of growing your website in 3 simple steps?