How to Add a MonsterLink to a WordPress Menu

Looking for an easy way to add a MonsterLink to your WordPress menu? Now you can with just a few easy steps. Follow this guide to add a MonsterLink to a WordPress menu.

  1. Add Link to WordPress Menu
  2. Add Attribute to Menu Item
  3. Enable MonsterLink Display Rule
  4. Go Live with Optin
  5. Troubleshooting
  6. FAQs

Step 1 – Add Link to WordPress Menu

We’ll start by adding a link to the WordPress menu that will become our MonsterLink.

Log into the WordPress admin, then navigate to Appearance > Menus and select the menu you wish to add a MonsterLink to.

Select the Custom Links tab to add a custom link. Enter a hashtag symbol (#) to the URL field, add your own custom Link Text and select the Add to Menu button before saving the changes to your menu.

The first step in adding a MonsterLink to your WordPress menu is adding a new custom link.

Step 2 – Add Attribute to Menu Item

To add the required data-optin-slug attribute to our MonsterLink menu item use the following filter added to your active theme’s functions.php file:

add_filter( 'nav_menu_link_attributes', 'ekf_menu_attribute_add', 10, 3 );
function ekf_menu_attribute_add( $atts, $item, $args )
{
  // Specify the menu item ID we want to add our attribute to
  $menu_link = 64;

  // Conditionally match the ID and add the attribute and value
  if ($item->ID == $menu_link) {
    $atts['data-optin-slug'] = 'jiqobgwsx9qinkci';
    $atts['class'] .= 'manual-optin-trigger';
  }
  //Return the new attributes
  return $atts;
}

We need to make two edits to this filter before it will work for our own MonsterLink.

First go ahead and grab the ID of your MonsterLink menu item. An easy way to do this is return to the Menu edit screen and hover over the Remove link for our MonsterLink, at the bottom of the browser window you can see the url preview for this link which also contains the Menu Item ID.

In the screenshot below, you can see where the url contains menu-item=64 and 64 is the ID of our MonsterLink.

You can preview the Menu Item ID by hovering over the Remove link in the Menu edit screen.

Second, you’ll need the slug of the optin you want to open when the menu item is selected. You can locate this by logging into your OptinMonster Dashboard – the slug is shown both below the optin’s Title and in the Edit button dropdown.

You can retrieve your optin slug from two places in the Dashboard view.

Once you’ve updated the filter with the menu item ID and optin slug go ahead and save the changes.

Step 3 – Enable MonsterLink Display Rule

While you’re logged into your OptinMonster Dashboard, open your optin in the builder and in the Display Rules panel enable the MonsterLink (On Click) option.

Enable MonsterLink loading for your optin in the Display Rules panel.

Step 4 – Go Live with Optin

The final step is ensuring your optin is Live in the OptinMonster API plugin.

Navigate to the WordPress Admin > OptinMonser > Optins tab view and select the Go Live link for your MonsterLink optin to enable it on your site.

You can enable your optin in the OptinMonster API plugin by selecting the Go Live link in the Optins list view.

That’s it! Now you can check out the new MonsterLink in your WordPress Menu in action!


Troubleshooting

If your site uses a custom walker class, the above filter will not work as expected. Instead, add the following to your active theme’s functions.php file and modify as indicated:


FAQs

Q: My menu item still isn’t triggering my optin to appear, why?

A: This will typically be caused by one, or several, of the following issues preventing your optin from being correctly triggered:

  • Custom Walker Class: your active theme may be using a custom walker class that you’re not aware of. You can check with the theme author to confirm if this is the case, then use the alternative method show in the Troubleshooting step above.
  • Incorrect Menu ID: double check the menu ID you’ve indicated in the filter added to your theme’s functions.php template file. If you add, then remove, then re-add the menu item to your site’s menu it will have a different ID than it did originally so keep that in mind if you make changes to your site’s menu.
  • Optin’s Output Settings Incorrect: if the optin’s embed code isn’t being output to the page there is no optin to be triggered to appear when the menu item is selected. From the WordPress Admin > OptinMonster > Optins tab view select the ‘Edit Output Settings’ link to check the Output Settings. If the menu is loading site-wide there should be no options within the Advanced Settings panel configured.