CSS - How to hide the 4th <li> without CSS class on WP Admin menu

33 views Asked by At

I have tried to hide the 4th

  • in a Wordpress Admin menu without luck.

    1. I have tried to access 4th

    2. without success. Here are my codes:

       HTML codes:
      
       <ul class="wp-submenu wp-submenu-wrap">
         <li class="wp-submenu-head" aria-hidden="true">Media</li>
         <li class="wp-first-item"><a href="upload.php" class="wp-first-item">Library</a></li>
         <li><a href="media-new.php">Add New</a></li>
         <li><a href="upload.php?page=webpc_optimization_page">Converter for Media</a></li>
       </ul>
      
      
       CSS codes:
      
         li.wp-submenu:nth-child(4) {
           display: none;
         }
      
       OR:
         li.wp-submenu-wrap:nth-child(4) {
           display: none;
         }
      
    3. I have also tried to hide it using PHP codes. Here is its link:

       URL:
      
       https://www.mywebsite.net/admin-cpanel/upload.php?page=webpc_optimization_page
      
       php codes:
      
       add_action( 'admin_init', 'hide_admin_menu_items' );
       function hide_admin_menu_items() {
            global $user_ID;
           if ( $user_ID != 1 ) {
             remove_menu_page('webpc_admin_page');      // Converter for media         // not working
         }
       }
      

    Please advise how to hide that 4th

  • from WP Admin menu.

    Many thanks in advance.

  • 1

    There are 1 answers

    0
    Gerard On BEST ANSWER

    You had the CSS wrong. li doesn't have class wp-submenu

    ul.wp-submenu li:nth-child(4) {
      display: none;
    }
    <ul class="wp-submenu wp-submenu-wrap">
      <li class="wp-submenu-head" aria-hidden="true">Media</li>
      <li class="wp-first-item"><a href="upload.php" class="wp-first-item">Library</a></li>
      <li><a href="media-new.php">Add New</a></li>
      <li><a href="upload.php?page=webpc_optimization_page">Converter for Media</a></li>
    </ul>