Remove &nbsp (blank space) from rtmedia-activity-text div


#1

Hi all,

When posting an update without text, a blank line appears, which takes up unneeded space.

How can I disable the &nbsp from appearing in the rtmedia-activity-text div when posting an update without text?

Thanks


#2

bump


#3

Hello @froster3,

BuddyPress do not allow to post an activity update without any text. To bypass this JavaScript validation, we have added &nbsp.

If we get any better alternative to this then will update it soon.

Thanks.


#4

Thanks for looking into it. I found a quick workaround and added this to child theme’s functions.php

add_filter('the_content', 'remove_empty_tags_recursive', 20, 1);
function remove_empty_tags_recursive ($str, $repto = NULL) {
         $str = force_balance_tags($str);
         //** Return if string not given or empty.
         if (!is_string ($str)
         || trim ($str) == '')
        return $str;

        //** Recursive empty HTML tags.
       return preg_replace (

              //** Pattern
              '~\s?<div class="rtmedia-activity-text">(\s|&nbsp;)+</div>\s?~',

             //** Replace without &nbsp if string empty.
             !is_string ($repto) ? '<div class="rtmedia-activity-text"></div>' : $repto,

            //** Source string
           $str
);}

#5

Has anyone else tried the code above? I added it to my functions.php but it doesn’t do anything.

BB Version 3.1.0 RTMedia Version 4.5.1

If the code above is invalid, can someone please point me in the right direction?

Thx


#6

This did the trick for me,

I created a new JavaScript file and added the following.

$(’.rtmedia-activity-text *’).contents().each(function() { if (this.nodeType === 3) { // text node this.textContent = this.textContent.replace(/\u00A0/g, ‘’); } });