• I’ve been trying to implement a function where if a person clicks a link from a specific referrer like “yoursite.com” a different Nav Menu will appear on the page it’s directed to.

    I’ve had a bit of success with:

    $referer_parse = parse_url($_SERVER['HTTP_REFERER']); 
       if(strpos($referer_parse['host'], 'yoursite.')!==false)  
          { 
             wp_nav_menu( array(
            'menu' => 'Replacement Menu'
    ) );
          }

    But the Primary Menu is still there and the Replacement Menu isn’t formatted properly.

    A little background as to why I’m trying to do this:
    The client sells items on their main domain (company1) via WooCommerce, but has another domain (company2) they wish to sell the same items. Seems to me you would have to set up a new WooCommerce store, which messes with item stock etc. My idea was to re-direct (company2) to (company1) but the client wants to avoid showing (company1) navigation if someone comes from (company2) – but maintain the (company1) navigation if they shop via (company1).

    In simpler terms…lol:

    1. Someone visits (Company1) and goes to the WooCommerce Shop – Primary Menu is fine.

    2. Someone visits (Company2) and it redirects to only the WooCommerce Shop at (Company1) but Primary Menu is not fine, should be a standalone Replacement Menu.

    How do I tell WordPress to only show Replacement Menu if a visitor comes via (Company2)

Viewing 2 replies - 1 through 2 (of 2 total)
  • You might just try this plugin instead https://themify.me/conditional-menus

    Looks like that will do exactly what you wish.

    Moderator bcworkz

    (@bcworkz)

    If you prefer custom code over a plugin solution, you are on the right track. You need to implement your code where your theme outputs the primary menu (where it calls wp_nav_menu(), usually header.php)

    Change your conditional into an if/else logic. In pseudo-code:

    referer = get-referer();
    if ( 'yoursite' == referer ) {
       nav-menu('replacement');
    } else {
       nav-menu('primary'); // theme's original call
    }
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Displaying a different Menu from Referrer’ is closed to new replies.