Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

Lay Theme Forum

  1. Home
  2. General Discussion
  3. Hide single menu item

Hide single menu item

Scheduled Pinned Locked Moved General Discussion
6 Posts 2 Posters 45 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qua7
    wrote on last edited by qua7
    #1

    Hi everyone,

    I have four items in menu 1 (portfolio, about, contact, blog). Is it possible to hide one item of this menu (portfolio) when the homepage (which is same as 'portfolio') is shown? I tried some custom php (see below), which hid the menu item 'portfolio' when on homepage. But it did not reappear automatically when navigating to a page or project, it only reappeared when I reloaded the page or project. How can this be fixed?

    add_filter('wp_nav_menu_objects', 'conditionally_hide_menu_item', 10, 2);
    function conditionally_hide_menu_item($items, $args) {
    if (is_front_page()) {
    foreach ($items as $key => $item) {
    if ($item->ID == 442) {
    unset($items[$key]);
    }
    }
    }
    return $items;
    }

    Q 1 Reply Last reply
    0
    • Q qua7

      Hi everyone,

      I have four items in menu 1 (portfolio, about, contact, blog). Is it possible to hide one item of this menu (portfolio) when the homepage (which is same as 'portfolio') is shown? I tried some custom php (see below), which hid the menu item 'portfolio' when on homepage. But it did not reappear automatically when navigating to a page or project, it only reappeared when I reloaded the page or project. How can this be fixed?

      add_filter('wp_nav_menu_objects', 'conditionally_hide_menu_item', 10, 2);
      function conditionally_hide_menu_item($items, $args) {
      if (is_front_page()) {
      foreach ($items as $key => $item) {
      if ($item->ID == 442) {
      unset($items[$key]);
      }
      }
      }
      return $items;
      }

      Q Offline
      Q Offline
      qua7
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • arminunruhA Offline
        arminunruhA Offline
        arminunruh
        Global Moderator
        wrote on last edited by arminunruh
        #3

        hey! its easier to use custom css

        the body tag has a slug and id. these are different based on the page you're on.
        also, the menu items have ids you can use to target them

        Screenshot 2025-03-03 at 16.40.33.png

        so for example

        body.slug-home #menu-item-3210{
        display: none;
        }
        

        Enter this css in "lay options" -> "custom css & html" -> "custom css for desktop"

        https://laytheme.com/documentation/custom-css-styling.html#css-based-on-current-page

        if you change the php code of the theme, it will be overwritten when lay theme updates

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qua7
          wrote on last edited by
          #4

          Thanks, @arminunruh! I added the CSS, but unfortunately it did not work. I tried body.type-category.id-1 #menu-item-442{
          display: none;
          }
          and I also tried:
          body.slug-portfolio #menu-item-442{
          display: none;
          }
          but both did not work.
          Can you have a look if you find the time? It is about this site: https://dagmarschwelle.com I want to hide the menu item PORTFOLIO when on page (category) portfolio.

          1 Reply Last reply
          0
          • arminunruhA Offline
            arminunruhA Offline
            arminunruh
            Global Moderator
            wrote on last edited by arminunruh
            #5
            body.slug-portfolio .menu-item-442{
            display: none!important;
            }
            

            seems like the menu had the class menu-item-442, not the id menu-item-442

            not sure why!

            does this css work?

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              qua7
              wrote on last edited by
              #6

              yes, it does! Many thanks, @arminunruh !!

              1 Reply Last reply
              1
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              I also code custom websites or custom Lay features.
              šŸ’æ Email me here: šŸ’æ
              info@laytheme.com

              Before you post:
              1. When using a WordPress Cache plugin, disable it or clear your cache.
              2. Update Lay Theme and all Lay Theme Addons
              3. Disable all Plugins
              4. Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"

              This often solves issues you might run into

              When you post:
              1. Post a link to where the problem is
              2. Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
              3. If the problem is difficult to explain, post screenshots / link to a video to explain it
              Online Users
              A
              alasdair17
              Forgot your key, lost your files, need a previous Lay Theme or Addon version? Go to www.laykeymanager.com
              laytheme.com
              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Recent
              • Tags
              • Popular
              • Users
              • Search