内容营销社交媒体和影响力营销
WordPress:为什么我删除评论(以及如何删除它们)
我删除了所有评论 Martech Zone 今天并禁用了我的孩子主题中的所有评论。 让我们讨论一下为什么删除和禁用 WordPress 网站上的评论是明智之举:
- 垃圾邮件预防: WordPress 网站上的评论因吸引垃圾邮件而臭名昭著。 这些垃圾评论可能会使您的网站变得混乱并损害您的在线声誉。 管理和过滤这些垃圾评论可能非常耗时且适得其反。 通过禁用评论,您可以消除这种麻烦。
- 未找到图像: 当我在网站上查找问题时,不断出现的一个问题是评论者放弃了使用 的gravatar,WordPress 显示评论者个人资料头像或图像的方式。 Gravatar 不会优雅地显示标准图像,而是会生成一个 文件未找到,减慢网站速度并产生错误。 为了纠正这个问题,我必须对评论者进行故障排除并删除它们……太耗时了。
- 保持链接质量: 允许在您的 WordPress 网站上发表评论可能会导致这些评论中包含外部链接。 其中一些链接可能来自低质量或垃圾网站。 搜索引擎在对您的网站进行排名时会考虑出站链接的质量。 禁用评论可以帮助您保持对网站上链接的控制,并防止潜在有害的链接影响您的排名。
- 时间效率: 管理和审核评论会极大地消耗您的时间和资源。 花在管理评论上的时间可以更好地用于与销售和营销工作相关的其他关键任务。 禁用评论可以腾出宝贵的时间来专注于内容创建、SEO 优化以及其他销售和营销活动。
- 转向社交媒体: 近年来,在线讨论的格局已从网站评论转向社交媒体平台。 用户更有可能在 Facebook、Twitter 或 LinkedIn 等社交媒体网站上分享、评论和互动您的内容。 通过将对话引导到这些平台,您可以进入更大、更活跃的社区并增强您的营销工作。
如何删除评论
运用 MySQL的 和 的phpMyAdmin,您可以使用以下命令删除所有当前评论 SQL 命令:
TRUNCATE TABLE wp_commentmeta;
TRUNCATE TABLE wp_comments;
如果您的 WordPress 表的前缀与 wp_
,您需要为此修改命令。
如何删除评论
此代码位于您的 WordPress 主题或子主题中 functions.php
文件是一组函数和过滤器,旨在禁用和删除 WordPress 网站上评论系统的各个方面:
// Disable comment feeds
function disable_comment_feeds(){
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
// disable comments feed
add_filter( 'feed_links_show_comments_feed', '__return_false' );
}
add_action( 'after_setup_theme', 'disable_comment_feeds' );
// Disable comments on all post types
function disable_comments_post_types_support() {
$post_types = get_post_types();
foreach ($post_types as $post_type) {
if(post_type_supports($post_type, 'comments')) {
remove_post_type_support($post_type, 'comments');
remove_post_type_support($post_type, 'trackbacks');
}
}
}
add_action('admin_init', 'disable_comments_post_types_support');
// Disable comments
function disable_comments_status() {
return false;
}
add_filter('comments_open', 'disable_comments_status', 10, 2);
add_filter('pings_open', 'disable_comments_status', 10, 2);
// Hide existing comments everywhere
function disable_comments_hide_existing_comments($comments) {
$comments = array();
return $comments;
}
add_filter('comments_array', 'disable_comments_hide_existing_comments', 10, 2);
// Disable comments menu in admin
function disable_comments_admin_menu() {
remove_menu_page('edit-comments.php');
}
add_action('admin_menu', 'disable_comments_admin_menu');
// Redirect users trying to access comments page
function disable_comments_admin_menu_redirect() {
global $pagenow;
if ($pagenow === 'edit-comments.php') {
wp_redirect(admin_url()); exit;
}
}
add_action('admin_init', 'disable_comments_admin_menu_redirect');
让我们分解每个部分:
disable_comment_feeds
:此功能禁用评论源。 它首先在主题中添加对自动提要链接的支持。 然后,它使用feed_links_show_comments_feed
过滤返回false
,有效地禁用评论源。disable_comments_post_types_support
:此函数会迭代 WordPress 安装中的所有帖子类型。 对于每个支持评论的帖子类型(post_type_supports($post_type, 'comments')
),它删除了对评论和引用的支持。 这有效地禁用了所有帖子类型的评论。disable_comments_status
:这些函数过滤前端评论和ping的状态返回false
,有效关闭所有帖子的评论和 ping。disable_comments_hide_existing_comments
:此函数通过返回空数组来隐藏现有注释comments_array
应用过滤器。 这可确保现有评论不会显示在您的网站上。disable_comments_admin_menu
:此功能从 WordPress 管理菜单中删除“评论”页面。 具有必要权限的用户将不再看到管理评论的选项。disable_comments_admin_menu_redirect
:如果用户尝试通过导航到“edit-comments.php”直接访问评论页面,此函数将使用以下命令将他们重定向到 WordPress 管理仪表板wp_redirect(admin_url());
.
此代码完全禁用 WordPress 网站上的评论系统。 它不仅禁用所有帖子类型的评论,还隐藏现有评论,从管理菜单中删除评论页面,并将用户重定向到评论页面。 当您不想使用评论功能并希望简化 WordPress 网站的后端时,这会很有帮助。