<?php | |
add_action('admin_init', function () { | |
// Redirect any user trying to access comments page | |
global $pagenow; | |
if ($pagenow === 'edit-comments.php') { | |
wp_redirect(admin_url()); | |
exit; | |
} | |
// Remove comments metabox from dashboard | |
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal'); | |
// Disable support for comments and trackbacks in post types | |
foreach (get_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'); | |
} | |
} | |
}); | |
// Close comments on the front-end | |
add_filter('comments_open', '__return_false', 20, 2); | |
add_filter('pings_open', '__return_false', 20, 2); | |
// Hide existing comments | |
add_filter('comments_array', '__return_empty_array', 10, 2); | |
// Remove comments page in menu | |
add_action('admin_menu', function () { | |
remove_menu_page('edit-comments.php'); | |
}); | |
// Remove comments links from admin bar | |
add_action('init', function () { | |
if (is_admin_bar_showing()) { | |
remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60); | |
} | |
}); |
This comment has been minimized.
This comment has been minimized.
Great and Thank you :) |
This comment has been minimized.
This comment has been minimized.
thanks! |
This comment has been minimized.
This comment has been minimized.
Don't forget to delete all existing comments ;] |
This comment has been minimized.
This comment has been minimized.
Great ! |
This comment has been minimized.
This comment has been minimized.
Great! |
This comment has been minimized.
This comment has been minimized.
Works like a charm, nice job. |
This comment has been minimized.
This comment has been minimized.
Works a treat |
This comment has been minimized.
This comment has been minimized.
Beautiful, there is a function for every plugin, indeed! Thank you this one! |
This comment has been minimized.
This comment has been minimized.
Great work, very useful, thanks a lot. |
This comment has been minimized.
This comment has been minimized.
Thanks! |
This comment has been minimized.
This comment has been minimized.
Useful, thanks. |
This comment has been minimized.
This comment has been minimized.
Thanks! |
This comment has been minimized.
This comment has been minimized.
Good work! |
This comment has been minimized.
This comment has been minimized.
Thank you |
This comment has been minimized.
This comment has been minimized.
For anyone interested in this, I cleaned it up a little bit: <?php
add_action('admin_init', function () {
// Redirect any user trying to access comments page
global $pagenow;
if ($pagenow === 'edit-comments.php') {
wp_redirect(admin_url());
exit;
}
// Remove comments metabox from dashboard
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
// Disable support for comments and trackbacks in post types
foreach (get_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');
}
}
});
// Close comments on the front-end
add_filter('comments_open', '__return_false', 20, 2);
add_filter('pings_open', '__return_false', 20, 2);
// Hide existing comments
add_filter('comments_array', '__return_empty_array', 10, 2);
// Remove comments page in menu
add_action('admin_menu', function () {
remove_menu_page('edit-comments.php');
});
// Remove comments links from admin bar
add_action('init', function () {
if (is_admin_bar_showing()) {
remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
}
}); |
This comment has been minimized.
This comment has been minimized.
Thank you @mattclements and @danielpost ! |
This comment has been minimized.
This comment has been minimized.
Great, thanks! This worked for me to remove the comments icon in admin bar add_action('wp_before_admin_bar_render', function() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('comments');
}); |
This comment has been minimized.
This comment has been minimized.
Great, Thanks!! |
This comment has been minimized.
This comment has been minimized.
Thanks, @mattclements and, @danielpost too. |
This comment has been minimized.
This comment has been minimized.
Can anyone tell me why the following line is not removed or hide existing comments? // Hide existing comments |
This comment has been minimized.
This comment has been minimized.
Your code has a flaw! It does not remove existing comment count in admin bar. function df_disable_comments_admin_menu() { This code is not working and is broken. init should be admin-init. See working code... function df_disable_comments_admin_bar() { |
This comment has been minimized.
This comment has been minimized.
Thanks @danielpost! I have updated the very old version that I had to yours, much cleaner and I think it covers all the other flaws that others have commented on. |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
Thank you. For a class that can be included then initialised with |
This comment has been minimized.
This comment has been minimized.
Still shows in the admin bar. Updating that portion to this and appears to work: https://www.isitwp.com/remove-comments-link-from-admin-bar/. |
This comment has been minimized.
This comment has been minimized.
Works perfectly, thanks! |
This comment has been minimized.
This comment has been minimized.
Thank you |
This comment has been minimized.
This comment has been minimized.
Thank you works great! |
This comment has been minimized.
This comment has been minimized.
Nice one - |
This comment has been minimized.
This comment has been minimized.
Thanks million :D |
This comment has been minimized.
No description provided.