怎么在Wordpress主题中添加代码
- 在wordpress后台 –> Appearance –> Theme Editor 中右上角选择要修改的主题,functions.php 最后添加代码:
function exitIntentpopup()
{
echo '<script type="text/javascript">';
echo 'window.onbeforeunload=function(e){';
echo 'e = window.event||e;';
echo 'if (e) {';
echo 'e.returnValue="Are you sure?";';
echo '}';
echo 'return "Are you sure exit?";';
echo '}';
echo 'document.addEventListener("mouseleave", function(e){ if( e.clientY < 0 ) { alert("Hey don\'t leave. I have an free eBook for you"); }}, false);';
echo '</script>';
}
add_action( 'wp_footer', 'exitIntentpopup', 100 ); // 注册后在footer.php 中才能调用;
- 打开footer.php文件在前面添加代码:
即可在主题页面中插入代码;刷新页面即可看到效果;