最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - Popup Maker nav menu item not working

programmeradmin2浏览0评论

I am trying to get my popup that I created using Popup Maker to show when clicking on one of my nav menu items. I found this tutorial here that explains 3 methods of doing so... NONE of them are working for me.

Going the route of the CSS class method in the tutorial, I could not get the CSS class to show on the anchor tag in the markup (or anywhere in the nav menu). I found that if I manually added the css class through the chrome debugger to the anchor tag, it would work. So...I also tried using this code to have php add the css class when the html is generated:

add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);

function special_nav_class($classes, $item){
     if($item->title == 'Request Maintenance Form'){
         $classes[] = 'popmake-1845';
      }
 return $classes;
} 

However, this code seems to do nothing. I'm a newbie to PHP so I'm not sure how to debug that code that I found.

Is my code wrong? Are there other known good methods that I should use instead?

Here is the configuration for the menu item:

P.S. I added a custom anchor tag in the header like so just to make sure the popup works. The pop up DOES work when clicking this tag so it's not a problem with the popup or the form:

<a class="request-maintenance-open" href="#contact_form_pop">Request Maintenance</a>

I am trying to get my popup that I created using Popup Maker to show when clicking on one of my nav menu items. I found this tutorial here that explains 3 methods of doing so... NONE of them are working for me.

Going the route of the CSS class method in the tutorial, I could not get the CSS class to show on the anchor tag in the markup (or anywhere in the nav menu). I found that if I manually added the css class through the chrome debugger to the anchor tag, it would work. So...I also tried using this code to have php add the css class when the html is generated:

add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);

function special_nav_class($classes, $item){
     if($item->title == 'Request Maintenance Form'){
         $classes[] = 'popmake-1845';
      }
 return $classes;
} 

However, this code seems to do nothing. I'm a newbie to PHP so I'm not sure how to debug that code that I found.

Is my code wrong? Are there other known good methods that I should use instead?

Here is the configuration for the menu item:

P.S. I added a custom anchor tag in the header like so just to make sure the popup works. The pop up DOES work when clicking this tag so it's not a problem with the popup or the form:

<a class="request-maintenance-open" href="#contact_form_pop">Request Maintenance</a>
Share Improve this question asked Jun 13, 2017 at 16:17 big_waterbig_water 1513 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

You can use something like this,

 add_filter( 'wp_nav_menu_items', 'your_custom_menu_item', 10, 2 );
    function your_custom_menu_item ( $items, $args ) {
        if ( $args->theme_location == 'Primary' ) { // change the menu location if not Primary
            $items .= '<a class="request-maintenance-open" href="#contact_form_pop">Request Maintenance</a>';
        }
        return $items;
    }
发布评论

评论列表(0)

  1. 暂无评论