怎么为WordPress文章发布按钮添加确认对话框

为WordPress文章发布按钮添加确认对话框,可以通过以下步骤实现:

怎么为WordPress文章发布按钮添加确认对话框
(图片来源网络,侵删)

1、打开WordPress后台,进入“外观”“编辑”,选择要编辑的主题的functions.php文件。

2、在functions.php文件末尾,添加以下代码:

// 为发布按钮添加确认对话框
function add_confirmation_dialog($content) {
    global $post;
    if (isset($post>ID)) {
        $content .= '<script type="text/javascript">
            document.getElementById("publish").onclick = function() {
                if (!confirm("确定要发布吗?")) {
                    return false;
                }
            };
        </script>';
    }
    return $content;
}
// 在发布按钮上显示确认对话框
add_filter('the_content', 'add_confirmation_dialog');

3、保存并关闭functions.php文件。

4、刷新WordPress后台,现在在点击发布按钮时,会弹出确认对话框。

注意:这段代码将确认对话框添加到了发布按钮上,如果需要将其添加到其他按钮上,可以修改document.getElementById("publish")中的"publish"为相应的按钮ID。

原创文章,作者:未希,如若转载,请注明出处:https://www.kdun.com/ask/485987.html

(0)
未希新媒体运营
上一篇 2024-04-18 02:54
下一篇 2024-04-18 02:56

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

云产品限时秒杀。精选云产品高防服务器,20M大带宽限量抢购  >>点击进入