[英]How can I set this pop up to only show/fire on the home page of the website?
我在这里有一个自定义弹出窗口https://odfigroup.com/ (像自定义插件一样使用 php 制作)
它过去只在有人在主页上并且只有一定数量的访问时才会触发,但它似乎不再起作用了。
所以我希望这个弹出窗口只显示在主页上。 并在每次有人达到这些访问计数时触发 [1,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45]; //在页面访问数上触发弹出窗口
这是我当前的代码
<?php
function od_cookie(){ //sets cookies - bound to init
if( !isset( $_COOKIE['odpop'] ) ){ // if cookie is not set set cookie to 1 ie first page load
setcookie('odpop', 1, 0, '/');
}else{
$count = intval($_COOKIE['odpop']) + 1;
setcookie('odpop', $count, 1, 0, '/'); // set cookie to session number
}
}
add_action('init','od_cookie');
function odpopwp_fire(){
$fireOn = [1,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45]; //fire popup on page visit number
if(isset($_COOKIE['odpop'])){ //If cookie is set
if(isset($_GET['odpop'])){ //if form has been submitted - GET REQUEST
include WP_PLUGIN_DIR . '/odonnell-popup/public/templates/success-template.php';
} elseif( in_array( $_COOKIE['odpop'], $fireOn ) == true ){//if cookie is equal to a value in $fireOn
include WP_PLUGIN_DIR . '/odonnell-popup/public/templates/odpopwp-template.php';
}
}else{ //if cookie is not set set the cookie.
include WP_PLUGIN_DIR . '/odonnell-popup/public/templates/odpopwp-template.php';
}
}
add_action('wp_footer', 'odpopwp_fire');
提前致谢!
如果您将主页设置为 static 主页,您将使用is_front_page()
。
if ( is_front_page() ) {
function odpopwp_fire(){
$fireOn = [1,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45]; //fire popup on page visit number
if(isset($_COOKIE['odpop'])){ //If cookie is set
if(isset($_GET['odpop'])){ //if form has been submitted - GET REQUEST
include WP_PLUGIN_DIR . '/odonnell-popup/public/templates/success-template.php';
} elseif( in_array( $_COOKIE['odpop'], $fireOn ) == true ){//if cookie is equal to a value in $fireOn
include WP_PLUGIN_DIR . '/odonnell-popup/public/templates/odpopwp-template.php';
}
}else{ //if cookie is not set set the cookie.
include WP_PLUGIN_DIR . '/odonnell-popup/public/templates/odpopwp-template.php';
}
}
add_action('wp_footer', 'odpopwp_fire');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.