Give a condition to a wordpress menu item to change its offerid for each landing page I create

So my wordpress site has a one header and one footer with a big CTA as one of the menu items. I want to create a bunch of landing pages but I want to be able to change the offerid in the url for each landing page for that big CTA so I can track.

By offerid I mean http://www.example.com/customers/?offerid=weyhw68963.

I'm am stuck on how to do this since the menu is a global menu and the link is the same on every page. My thought is that I would make a condition in the header.php file because I'm using bootstrap and I activated the menu in the header file.

    ?php
    if(is_front_page()) {
        $args = array(
              'menu'         = 'header-menu',
              'menu_class'   ='nav navbar-nav navbar-right',
              'container'    ='false'
              );
      } else {
        $args = array(
              'menu'         = 'page-menu',
              'menu_class'   ='nav navbar-nav navbar-right',
              'container'    ='false'
              );
      }
      wp_nav_menu( $args );

     ?

I'm thinking something like starting with is_page("offerid") then using custom_key but to be honest I'm very lost.

Topic conditional-content menus Wordpress

Category Web


What about using jQuery to insert the unique code to your CTA menu class or item ID? Something like:

    // generate your unique codes in jQuery
    var mycode = your_random_code_function() // or an array of codes
    // then…
    var myhref = $("body.landingpage .navbar-nav .cta a").attr("href"); 
    $("body.landingpage .navbar-nav .cta a").attr("href", myhref + "?offerid=" + mycode);
    // etc…
    // add the .cta class to the menu item that needs a code via Appearance > Menus in WP
    // or just use its WP generated ID

Otherwise I think you'd have to look at a custom walker class.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.