
子比主题更新到8.7版本后,频繁提示“确认离开”,例如:发布文章、离开已发布…
这段代码通过WordPress注入JS,禁用了后台文章/页面编辑页的“未保存离开”提示。
代码添加到: /wp-content/themes/zibll/func.php或function.php 文件里
add_action('admin_footer', function () {
$screen = get_current_screen();
if (!$screen) return;
if ($screen->base === 'post' || $screen->base === 'post-new') {
?>
<script>
(function() {
window.onbeforeunload = null;
const oldAdd = window.addEventListener;
window.addEventListener = function(type, listener, options) {
if (type === 'beforeunload') {
return;
}
return oldAdd.call(this, type, listener, options);
};
document.addEventListener('DOMContentLoaded', function() {
window.onbeforeunload = null;
});
setInterval(function() {
window.onbeforeunload = null;
}, 500);
})();
</script>
<?php
}
});
不知道各位站长有没有这个困扰…也可能是我禁止了自动保存导致的。






