Title: Hide show comments button
Last modified: June 2, 2023

---

# Hide show comments button

 *  Resolved [havenwebmanagement](https://wordpress.org/support/users/havenwebmanagement/)
 * (@havenwebmanagement)
 * [3 years ago](https://wordpress.org/support/topic/hide-show-comments-button/)
 * This really needs to be a feature in the plugin. The wall gets taken up by too
   many comments. The problem with the following code that was posted is the button
   always shows if there is no comment made. Needs to only show when a comment is
   made. The other issue is this breaks replies to the comments Ajax load like it
   normally does. You have to refresh the page to see any nested comments or replies
   to replies. Is there any way to add this as a feature or fix the code that was
   posted?
 *     ```wp-block-code
       <?php
       add_action( 'wp_footer', 'add_comment_hide_show' );
       function add_comment_hide_show() {
           ?>
           <style>
               .activity-comments ul li[id^="acomment-"]{display: none;}
           </style>
           <script type="text/javascript">
               jQuery(function($) {
                   setInterval(function() {
                       $('.activity-meta').each(function() {
                           if( !$(this).find('.show-comments').length ){
                               var html = '<a href="#" class="button bp-primary-action show-comments">Show/Hide Comments</a>';
                               $(this).find('.button.acomment-reply').after(html);
                           }
                       });
                   }, 500);
                   $('body').on('click', '.show-comments', function(e) {
                       e.preventDefault();
                       var obj = $(this).closest('.activity-content').next('.activity-comments').find('ul li[id^="acomment-"]');
                       obj.slideToggle();
                       return false;
                   });
               });
           </script>
           <?php
       }
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Support [Youzify](https://wordpress.org/support/users/kainelabsteam/)
 * (@kainelabsteam)
 * [3 years ago](https://wordpress.org/support/topic/hide-show-comments-button/#post-16790542)
 * Hello [@havenwebmanagement](https://wordpress.org/support/users/havenwebmanagement/)
 * Thank you for reaching us
 * At the moment, indeed hide/show button only can be achieved with that snippet.
   However, we will consider to make this as a feature in the future updates. 🙂
 * Best Regards, KaineLabs Team.
 *  [Diabolo](https://wordpress.org/support/users/cebuss/)
 * (@cebuss)
 * [2 years, 12 months ago](https://wordpress.org/support/topic/hide-show-comments-button/#post-16817378)
 * [@havenwebmanagement](https://wordpress.org/support/users/havenwebmanagement/)
 * How did you go with this, found a solution?
 * If not, try the following version. NB I don’t even pretend to know what I’m doing
   so it’s definitely not the most elegant solution, just trial and error – hopefully
   someone that does know what they are doing will see this and tidy it up! That
   said, it works for me, with a couple of caveats (not related to this snippet).
 *     ```wp-block-code
       function add_show_hide() {
       ?>
       <style>
       .single-group .activity-comments ul{display: none;}
       </style>
       <script type="text/javascript">
       jQuery(function($) {
       	setInterval(function() {
       		$('.youzify-activity-statistics').each(function() {
       			if( !$(this).find('.show-comments').length ){
       				var html = '<a href="#" class="bp-primary-action show-comments" style="float: right; margin-left: 3px; margin-top: 23.75px; color: #f30707; font-size: 13px; font-weight: 900;">- show/hide</a>';
       				$(this).find('.youzify-post-comments-count').before(html); 
       			}
       		});
   
       	}, 500);
   
       	$('body').on('click', '.show-comments', function(e) {
       		e.preventDefault();
       		var obj = $(this).closest('.activity-content').next('.activity-comments').find('ul');
       		obj.slideToggle();
       		return false;
       	});
   
       });
       </script>
       <?php
       }
       add_action( 'wp_footer', 'add_show_hide' );
       ```
   
 * **Your concerns:**
 * _The problem with the following code that was posted is the button always shows
   if there is no comment made._
 * Not with the above (see screencast demo below). Also note I moved where it shows
   up (seemed somewhat disconnected to me in the default position, slightly worried
   it may go unnoticed now so changed the colour).
 * _Needs to only show when a comment is made._
 * Does with this snippet.
 * _The other issue is this breaks replies to the comments Ajax loads like it normally
   does. You have to refresh the page to see any nested comments or replies to replies._
 * Replies show up as soon as Ajax does its thing (again, see screencast).
 * **Caveats:**
    1. The actual comment count doesn’t increase until a page refresh. Personally, 
       I see that as a bug and have just posted as such.
    2. Personally I’d prefer the comments to be collapsed as default. Still looking
       into that so if anyone has any ideas please share 🙂
 *  -  This reply was modified 2 years, 12 months ago by [Diabolo](https://wordpress.org/support/users/cebuss/).
    -  This reply was modified 2 years, 12 months ago by [Diabolo](https://wordpress.org/support/users/cebuss/).

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Hide show comments button’ is closed to new replies.

 * ![](https://ps.w.org/youzify/assets/icon-256x256.png?rev=2487434)
 * [Youzify – BuddyPress Community, User Profile, Social Network & Membership Plugin for WordPress](https://wordpress.org/plugins/youzify/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/youzify/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/youzify/)
 * [Active Topics](https://wordpress.org/support/plugin/youzify/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/youzify/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/youzify/reviews/)

## Tags

 * [button](https://wordpress.org/support/topic-tag/button/)
 * [Comments](https://wordpress.org/support/topic-tag/comments/)
 * [replies](https://wordpress.org/support/topic-tag/replies/)

 * 2 replies
 * 3 participants
 * Last reply from: [Diabolo](https://wordpress.org/support/users/cebuss/)
 * Last activity: [2 years, 12 months ago](https://wordpress.org/support/topic/hide-show-comments-button/#post-16817378)
 * Status: resolved