Skip to:
Content
Pages
Categories
Search
Top
Bottom

How To Hide Comments From Activity Stream


  • silvep4
    Participant

    @silvep4

    I am interested in “Show/Hide Comments” and I found the following code for that :

    add_action( 'wp_footer', 'add_comment_hide_show' );
    function add_comment_hide_show() {
        ?>
        <style>
        .single-group .activity-comments ul{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');
    	obj.slideToggle();
            return false;
          });
    
        });
        </script>
        <?php
    }

    And it is working good when I add it to functions.php but the problem is that by default it shows all the comments and it hides the comments when we click on the “Show/Hide Comments” button. Can anybody edit it so that by default it hides the comments and when we click on the button then it shows the comments.

    Thanks.

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

  • shay1383
    Participant

    @shay1383

    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 = ‘Show/Hide Comments‘;
    $(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
    }


    shay1383
    Participant

    @shay1383

    sorry, copy that one:

    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
    }

    lalaloo
    Participant

    @lalaloo

    Probably related to recent updates, but neither options on this thread work anymore.


    @silvep4
    – Your code doesn’t hide the comments.

    @shay1383
    – Your code does hide the comments but, then on click, nothing happens. It doesn’t show the comments.

    Can anyone help?


    lalaloo
    Participant

    @lalaloo

    bump

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar