如何通过代码触发Elementor Popup

问题描述

这里有人使用Elementor吗?您如何通过代码触发弹出窗口?例如。

function popup_call(){
    ...
    if(....){
        //trigger the popup here...
    } 
}

解决方法

这个问题已经回答:

XML GENERATE

https://github.com/elementor/elementor/issues/7077#issuecomment-595570337

或尝试将弹出窗口绑定到按钮,用CSS隐藏该按钮

// accessible on window.elementorProFrontend
elementorProFrontend.modules.popup.showPopup( { id: 123 } );

并在js中使用click(jquery)

.yourbtn {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0);
  border: 0;
}

https://github.com/elementor/elementor/issues/7077#issuecomment-595570337

如果第二种方法对您有帮助,请不要忘记在屏幕阅读器中隐藏按钮 aria-hidden =“ true”和tabindex =“-1”

,

Elementor的弹出窗口需要注册和触发。 This主题可能会对您有所帮助。

使用wp_footer钩子注册弹出窗口。

add_action( 'wp_footer','your_popup_function',10,5);
function your_popup_function(){
    
    if(..assuming your condition is true..){
        
        $popup_id = '2409'; //your Popup ID.
        ElementorPro\Modules\Popup\Module::add_popup_to_location( $popup_id ); //insert the popup to the current page

        ?><script>
        jQuery( document ).ready( function() { //wait for the page to load
            /* You can do more here,this will just show the popup on refresh of page,but hey this is JQuery so you can do more things here depending on your condition to trigger the popup */
            jQuery( window ).on( 'elementor/frontend/init',function() { //wait for elementor to load
                elementorFrontend.on( 'components:init',function() { //wait for elementor pro to load
                    elementorFrontend.documentsManager.documents[<?php echo $popup_id ;?>].showModal(); //show the popup
                } );
            } );
        } );
         </script>;
         <?php
    }
    
    return; //return nothing by default and do not show the popup.
 }

阅读评论以获得更多说明。

,

我不知道您为什么需要代码,如果您需要单击打开一个弹出窗口,而没有在浏览器的底部显示url(像标记一样工作),请尝试“自定义类”。 / p>

,

对我来说,它在 Wordpress 5.7.2 和 elementor pro 3.2.1 上是这样工作的

function popup_call(){
...
if(....){
    //trigger the popup here...
    echo"<script>  window.onload = function() {   
    elementorProFrontend.modules.popup.showPopup( {id:13000},event);    }  
    </script>";
} 
  }

只需设置 ID

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...