文章页禁止文本选择和右键
在single.php页面添加以下代码
function disable_right_click() {
echo ‘<script>
document.addEventListener(“contextmenu”, function(e) {
e.preventDefault();
});
</script>’;
}
add_action(“wp_head”, “disable_right_click”);
function disable_right_click_drag() {
echo ‘<script>
document.addEventListener(“contextmenu”, function(e) {
e.preventDefault();
});
document.body.style.userSelect = “none”; // 禁止选择
</script>’;
}
add_action(‘wp_footer’, ‘disable_right_click_drag’);