Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

How do I approach removing menu items on the fly based on settings in my plugin?

Well an easy solution is CSS

<!--    HIDES MENU ITEM IF THE USER IS NOT LOGGED IN   -->
<?php if (is_user_logged_in()){
echo "";}
else {
echo "<style type="text/css">
.menu-item-58 {display:none;}
</style>";
};
?>

But if you are trying to code it down see the source of this plugin http://wordpress.org/extend/plugins/if-menu/ — it will help you alot.

While if you just want a coding answer – a simple one – replace the header

<ul>
  <?php wp_list_pages(); ?>
</ul>

With the conditional statement

if user not logged in
show
<ul>
  <?php wp_list_pages('exclude=17,38' ); ?>
</ul>

where exlude are the pages id you don’t want a not logged in user to see.

while using else commend to show all menu to logged in user

else 
<ul>
  <?php wp_list_pages(); ?>
</ul>

Hope this helps you. keep us up to date.

Related Posts:

  1. Change the_title() of a page dynamically
  2. Create a Page via plugin
  3. How to create archive page to add in menu
  4. add_menu_page() with different name for first submenu item
  5. Get page content using slug
  6. How to add sub-menu to a menu generated by wp_nav_menu by using plugin
  7. How do I programatically insert a new menu item?
  8. Can someone explain what wp_session_tokens are, and what are they used for?
  9. Add Dividers or Separators Between Nav Menu Items
  10. Init action hook running late after PayPal’s return url?
  11. Nav Menu meta failing to import
  12. How to check WordPress website username and password is correct
  13. How to edit the properties of a page programmatically?
  14. Log in from one wordpress website to another wordpress website
  15. Problems after wp_set_password() containing an apostrophe
  16. Overwriting Core WordPress Functions with Plugins
  17. Some nav-menu filters do nothing
  18. Determine which theme location a wp_get_nav_menu_items is for
  19. Pages 404 in wordpress
  20. Can I add pages to my custom menu via script?
  21. Replacing WordPress menu functionality with a plugin
  22. Two-step login process – Is it possible?
  23. How to create a dynamic page based on form data with a plugin?
  24. Use an empty page to build custom plugin output
  25. Is it possible for a plugin to register a page template file?
  26. Is it possible to show a different WP menu when using password protected pages?
  27. Hook event for upload image in the menu
  28. Dropdown list of pages to get page id to store in plugin options
  29. Calling a function from functions.php in custom page/ blog post
  30. Why isn’t the Settings API designed to work for plugins using custom admin menus? [duplicate]
  31. Set a specific page as 404 – not found via my own plugin
  32. What is the difference between current_page_parent and current_page_ancestor?
  33. Making WordPress’ page and menus visible only for logged in users, checking session variables
  34. Delete a specific item menu when I deactivate my plugin
  35. Add Submenu Link in add_submenu_page That Opens in a New Window
  36. How to assign a WP 3.0 custom nav menu to a theme’s navigation menu location via script?
  37. Header Button Chance Polylang Elementor
  38. PHP 7 – Class Method Compatibility Issue
  39. How to add pages to custom menus on the fly [duplicate]
  40. How do I add a custom sublevel menu specified in one directory to a custom top level menu specified in another directory?
  41. Add notification bubble notice in navigation using transients
  42. Is there any way to check for user login and send him to login?
  43. Proper way to pass credentials in a custom login form to avoid “headers already sent”
  44. Get Current Menu Location inside Nav_Walker
  45. External Authentication, session_tokens not destroyed on logout
  46. Verify if user is wordpress logged in from another app since wordpress 4.0
  47. Adding custom fields to WordPress nav menus
  48. Sub Menu content is being duplicated
  49. How to customize login process
  50. Secure Pages Best Practice
  51. Plugin menu addition in multisite
  52. wp_insert_user() function password never match
  53. Does wp_login only trigger before an user signs in into the admin panel?
  54. Logout users upon login, based on caps/role?
  55. Remove unwanted elements for a wp_nav_menu
  56. Is this best practice for Dynamically adding items to WordPress menus?
  57. Is it possible to make sure that only my plugins output is shown to the enduser?
  58. Password field is empty when using wp_signon();
  59. How to remove or add submenu item on plugin activate or deactive
  60. Plugin Development for registered users
  61. Custom code for WordPress dynamic menu
  62. Plugin generated virtual pages
  63. How do I access the menus produced by Dashboard > Appearance > Menus
  64. Enqueue script globally
  65. WP Multisite login not working on one subsite. Possibly cookies/ history issue?
  66. wordpress add_submenu_page adds broken link
  67. Add Password Generator on password protected page
  68. WP Enqueue style on all plug-in pages
  69. Add child pages to submenu automatically
  70. Customize existing menu item
  71. ECHO Executing 4 Times In Head
  72. WordPress pages are not published due to External database connection with WPDB class
  73. Menu page with minimum capability as ‘Subscriber’ doesn’t allow ‘Admin’ to access it?
  74. Create page (not the post type) dynamically
  75. Multiple array for post_content on plugin activation
  76. How do I validate extra pin field on my WordPress login form page?
  77. Issue with plugin sub menu and pages
  78. How to redirect home page to another page after login for all user?
  79. How to add Plugin functionality in WordPress Frontend Menus
  80. How to list all images used on a specific page?
  81. Create fixed static pages
  82. How to hide page links from theme menu
  83. WP_NAV_MENU filter targets all menus
  84. How do I add a menu item to a Pods admin menu?
  85. How to share user data across multiple WordPress websites?
  86. Add user managable titles to custom menus?
  87. Set page to draft on plugin deactivation
  88. Load specific page when a custom URL is hit
  89. How to show only the last two categories in a menu?
  90. Allowing duplicating users with same user_login and user_email
  91. How to Login a User inside a Plugin and Redirect to page?
  92. Using custom IDP with WP
  93. Plugin frontend page design irrespective of the theme used
  94. Hiding the WordPress login and password fields from login page
  95. Custom non-template page on front end fails to render
  96. Always hide a page from the menu
  97. remove different admin menu for specific users
  98. redirect_to how to make it simply work with get parameter or similar?
  99. Using WP page password protection as defacto login
  100. How to get an array out of a nav menu if it’s a plugin?
Categories plugin-development Tags login, menus, pages, plugin-development
Target all posts that are NOT aside or link post formats
how do i combine keyword search and taxonomy in a WP_query $args array Worpresss [closed]

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress