Support » Fixing WordPress » How to Hide the website main menu or all the header only on alias domains

  • Resolved rtask609

    (@rtask609)


    Hello,
    [ redundant link removed ]

    i need to hide the main menu or the whole header on alias domains , how can i accomplish this on my main website

    i already know whats the Class and ID for the HTML Tags for related for the menu and the header , but i need to know how to manage to hide the header or the menu just on the alias domains,

    Best Regards,
    Ramy.

    • This topic was modified 2 weeks, 2 days ago by  rtask609.
    • This topic was modified 2 weeks, 2 days ago by  rtask609.
    • This topic was modified 2 weeks, 2 days ago by  Jan Dembowski.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    CSS doesn’t know anything about which domain was requested, so the solution needs to involve some custom PHP somewhere. (TBH, a JavaScript option may be possible, but it would be very sub-optimal). I assume the requested alias domain is in $_SERVER somewhere. If that value is not the main domain, PHP ought to output a special body class such as “noheader”. Assuming your theme uses the body_class() function to set body classes, you can use the “body_class” filter to conditionally add “noheader” to the list of classes.

    Then you can prepend .noheader to the ID and class selectors you already know about and specify display: none; CSS rule in order to hide the elements when “noheader” class is present.

    Hello,

    thank you very much for the reply,

    i was able to solve the problem after following your guidance even though i am not a php guy, i am a .net and smart card developer :

    For others to know:

    1-To get the Link from the browser i used this code:

    <?php 
    // Program to display current page URL. 
      
    $link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 
                    "https" : "http") . "://" . $_SERVER['HTTP_HOST'] .  
                    $_SERVER['REQUEST_URI']; 
      
    echo $link; 
    ?> 

    you can find it here.

    2- i added a class (“noheader”) to the body_class("noheader") method as you suggested

    the final code in the header.php looks like this :

    	  <body <?php 
    		  
    	  $link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 
                    "https" : "http") . "://" . $_SERVER['HTTP_HOST'] .  
                    $_SERVER['REQUEST_URI']; 
    
    		 $Main = strpos($link, 'domainerme.com');
    		  if ($Main){
    			   body_class();
    		  }else{
    			    body_class('noheader');
    		  }
    		  	 
    
    		  ?>>

    CSS
    for me it looks like this:

    .noheader .main-navigation {
    		display:none;
    }

    Best Regards,
    Ramy,

    • This reply was modified 2 weeks, 1 day ago by  rtask609.
    Moderator bcworkz

    (@bcworkz)

    Nicely done sir. Being any kind of developer gives you a big leg up over most people, even when faced with an alien language.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.