Please note: the text above: $menu_target and the $item->ID number to the right of the == will need to be replaced with the id numbers of the menu items.

In the above instance, we’re adding custom link attributes to 3 different menu items. The menu items with id’s: 1075, 2725, and 1109.

We’re adding a category of CTA to all links and a unique custom label to each link.

Step 1: To find the ID of the navigation menu items in WordPress on your own site, right-click on the navigation menu item in your web browser:

Step 2: Next, click “inspect” or “inspect element.”

You’ll then see the source code of the website:

Step 3: What we’ll be looking for next is the unique id number associated with the <a> link element that WordPress assigns to menu link elements:

And as you can see, it’s 1102.

Step 4: Be sure to use your own unique ID numbers for your specific navigation links.

Step 5: You’ll also want to replace the label with whatever makes sense for your site. Or remove it to leave the default.

Step 6: You can also add a custom event action or leave the default. (This typically defaults to the full URL of the link)

Step 7: Next, you’ll want to navigate to the functions.php file of your theme or functionality plugin, and insert your own code that you’ve customized for your site.

If you only need to track one or two menu items, the other elseif statements can be removed. Similarly, feel free to add more elseif statements. Remember: it’s best to only track important events. Otherwise, you’ll have a lot of irrelevant data clouding those decisions.