Add UTM Parameters to WordPress Menu Items

We’re working on use case-focused documentation and getting started guides over at Paid Memberships Pro.

For this effort, I also needed to add direct links to our most popular use cases in our site’s footer—and I need these links to have unique UTM parameters so I can track which use cases are getting the most interactions.

Here’s a quick code recipe to demonstrate using the nav_menu_link_attributes filter to extend a wp_nav_menu.

Screenshot of menu items with UTM parameters added via filter

Yes, you can do this without code.

Another option I considered was using Custom Links in my nav menu and hard coding the UTM parameters. That’s a great no-code approach to achieve the same result—but in this case I will eventually change the link items (to the full use case landing page for each type) and felt this was an easier approach for long term stability.

The Code Recipe

Adding the Recipe to Your Website

You can add this recipe to your site by creating a custom plugin or using the Code Snippets plugin available for free in the WordPress repository. We have a post on how to create a customizations plugin on our partner website, Paid Memberships Pro.

Default image

Kim Coleman

Hi! I'm Kim Coleman, an internet entrepreneur from Reading, Pennsylvania. I've been working with WordPress for over 15 years. In 2011, I founded Paid Memberships Pro, a complete plugin for Recurring Subscriptions and Content Restriction with 100k active sites. I'm currently working on our new product, Sitewide Sales.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.