Okay, the solution is this below to hide Comments menu if the site doesn’t have any comments (approved, pending, trash or spam).
function remove_commentsmenu() {
global $user_ID;
if ( 1 > wp_count_comments( get_the_ID() )->total_comments && 1 > wp_count_comments( get_the_ID() )->trash ) {
remove_menu_page( 'edit-comments.php' );
}
}
add_action( 'admin_menu', 'remove_commentsmenu' );
Related Posts:
- Adding button to wordpress menu
- start_lvl Ignored in Custom walker_nav_menu
- Menu Items Disappearing
- wp_delete_auto_drafts() deletes links in menus
- Check if a menu is empty?
- Walker class: Problems with understanding how walk() method can be called without error
- count number of user comments with a specific comment meta value
- Replacing a specific menu item
- Change comments form title on a page by page basis
- How can I access the “description” of a menu item?
- Add value to usermeta without removing previous values?
- Notify WordPress Site I Have Linked To Them
- Replace comment avatars and links at the same time
- How can I add a custom class to only nav sub-menu > li > a items in WordPress?
- Adding ads code between comments
- items_wrap not working
- Style wp_page_menu() items
- Have CSS Class Added with `is_page()` WP function
- Run a filter when a walker runs
- comments_number display outside specified span
- Trying to implement Ajax comments in WordPress, getting WP error
- Remove one value in dismissed_wp_pointers?
- Multiple WordPress Menus that will only display all pages
- WP Walker using custom css classes
- Change list item content in menu navigation to add a child element with specific class
- “comments.php” not available after edit in WP administration
- Sending data from custom inputs in WordPress comment form in the admin notification email
- Automatically adding new post categories to menu
- Show wp_die if url form comment not emply
- Customize Theme comment template to Insert VoteUp and VoteDown buttons
- How to implement a rating and review system for WordPress custom posts?
- Child page menu in sidebar
- Title Case WordPress Menu Items
- Limit 1 global comment per minute
- Commenting out unwated CSS/scripts in HTML with PHP
- Trying to store submenu items to render out after main menu
- php function to display commenter username or login
- How to change menu order item
- check if comment submitted was successful
- Alter required message using comment form api
- Two menus show up
- Register a menu – Error Header
- Parsing Menu Items and Blog Posts
- Does anyone know all parameters of get_comments()
- How to create a field in customize and show that in header.php?
- Send a mail to specific address in a custom field when a new comment is made on a specific post
- Add value to new attribute inside WordPress menu items
- Menu Items fail to save correctly, cause reset of related page metadata
- Dropdown menu for categories
- How to display different submenus?
- Get the name of menu item with wp_nav_menu
- Output only links using wp_nav_menu()
- How to add aria role and schema markup to custom walker container
- Warning: call_user_func() expects parameter 1 to be a valid callback, function
- Restrict characters in comment section
- Extend Menu Walker Output
- How to debug failed changes to posts?
- how to add a div inside wp_page_menu
- How to correctly load a different version of main menu based on the user language in WordPress? Is it a good solution?
- Why can’t I add a custom image in my navigation?
- Remove submenu item from list
- conditional: if is page, and all subpages
- I don’t have comments.php… how do I customize my comment fields
- Remove the Tag from wp_nav_menu
- Dynamic menu with custom post types
- Adding an Anchor Link to a wordpress menu using WPBakery Page Builder
- How to make only the valid active page of a multilevel menu active with – “.nav li.current-menu-item a”?
- Replace jQuery with PHP or CSS for Customized WordPress wp_nav_menu
- How to put 2 php codes in functions.php without site crashing
- wp_get_nav_menu_items() with ACF
- How to switch between two primary menus (programatically0
- Redirect User when they click Menu Option
- Used a code to revoke some dashboard menus for my contributors but for some reason it’s revoked me access to the editor [closed]
- Closing Comments conditionally in comments.php
- How to give custom roles the capability to edit one Menu instead of every Menu
- Primary navigation menu with timed items from custom post type
- Difference between “Walker_Nav_menu” and “walker”
- Fatal error when using array_diff() function inside of wp_update_nav_menu hook?
- Vertical Menu for one page only
- How limit the width of a fixed menu-bar on scroll?
- How can I enqueue comment-reply script only on certain page?
- Pulling a variable into the wp_nav_menu function
- Beyond widget side menu editing, with the php page, custom template
- Two theme locations for two menus, but only one is showing up
- wp nav menu without label
- Contact form field in wordpress menu
- How to call a certain object/menubar in a PHP file
- Sidebar current menu item for parent
- Remove all nav menu classes except those which begin with certain letters
- How to add a code for lastpostdate after/inside a specific menu link?
- Add the “.current-menu-item” class to tag?
- WordPress adding in site URL to header links
- How to change the menu color
- Can’t remove menu items added by plugin
- Nav Menu Display
- Adding a unique class to wp_nav_menu
- Catchable fatal error in appcloud free theme by Tokokoo
- Custom Navigation Bar JSON Syntax Error in JSON at Position 0
- Guests comment form – prevent duplicate email addresses
- Error when loading Dashboard