从菜单项启动邮件黑猩猩弹出窗口

时间:2019-05-27 作者:huntlake

我正在尝试添加一个菜单项,单击该菜单项将打开Mailchimp弹出窗体。虽然我熟悉VBA和Access开发,但我对Web/WordPress开发的知识有限。

以下是我迄今为止根据在线研究尝试的代码片段:

1) 我在几个不同的网站上找到了这个。问题是,似乎没有任何方法可以让它从菜单项启动。

<script type="text/javascript" src="//downloads.mailchimp.com/js/signup-forms/popup/unique-methods/embed.js" data-dojo-config="usePlainJson: true, isDebug: false"></script>

<script type="text/javascript">
  function showPopup() {
      window.dojoRequire(["mojo/signup-forms/Loader"], function(L) { L.start({"baseUrl":"mc.us20.list-manage.com","uuid":"YOUR_UUID_GOES_HERE","lid":"YOUR_LID_GOES_HERE","uniqueMethods":true}) });
//unsetting the cookie
  document.cookie = "MCPopupClosed=; expires=Thu, 01 Jan 1970 00:00:00 UTC";                  
  document.cookie = "MCPopupSubscribed=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
  }

  document.getElementById("show-popup").onclick = function() { showPopup(); }
</script>
2) 这是我第二次尝试。

<script type="text/javascript" src="//downloads.mailchimp.com/js/signup-forms/popup/unique-methods/embed.js" data-dojo-config="usePlainJson: true, isDebug: false"></script>

<script type="text/javascript">
  jQuery(document).ready(function($) {
      $("menu-item-364").on("click",function showPopup() {
      window.dojoRequire(["mojo/signup-forms/Loader"], function(L) { 
          e.preventDefault();
          L.start({"baseUrl":"mc.us20.list-manage.com","uuid":"YOUR_UUID_GOES_HERE","lid":"YOUR_LID_GOES_HERE","uniqueMethods":true}) });


////unsetting the cookie
  document.cookie = "MCPopupClosed=; expires=Thu, 01 Jan 1970 00:00:00 UTC";                  
  document.cookie = "MCPopupSubscribed=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
  });
 });


document.getElementById("show-popup").onclick = function() { showPopup(); }
我还阅读了另一篇帖子,其中有人建议使用addEventListener onhashchange事件来启动该功能,a)我无法让它工作,b)我担心它会在标签更改的任何时候启动,如果我将来使用锚导航到网站的其他区域,会导致问题。

我错过了什么?

1 个回复
SO网友:Milan Hirpara

我使用引导弹出窗口和mailchimp短代码找到了解决方案。

您需要安装mailchimp插件。https://wordpress.org/plugins/mailchimp-for-wp/

Step 1 : Customise menu item

function nav_replace_wpse_189788( $item_output, $item, $depth, $args ) {
 //var_dump($item_output, $item);
    if( $args->theme_location != \'main_menu\' ){
        return $item_output;
    }

    if ( $item->menu_order == \'3\' ) {
        $item_output .= \'<li class="moblie-nav menu-item menu-item-type-custom menu-item-object-custom last-menu-item">\';
        $item_output .= \'<a href="JavaScript:Void(0)" data-toggle="modal" data-target="#myModal">Subscribe</a>\';
        $item_output .= \'</li>\';
    }

    return $item_output;
 }
 add_filter(\'walker_nav_menu_start_el\',\'nav_replace_wpse_189788\',10,4);

Step 2 : Add popup with mailchimp shordcode

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" 
   aria-labelledby="myModalLabel" aria-hidden="true">
   <div class="modal-dialog">
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                 <img src="images/close-icon.png">
            </button>
         </div>
         <div class="modal-body">
            <div class="exp_login_wrap">
                <h3>Subscribe</h3>
                <?php echo do_shortcode( \'[mc4wp_form id="26125"]\' );?>

            </div>
         </div>
      </div><!-- /.modal-content -->
   </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

相关推荐