• Hi guys,

    i am using shortcodes. After each shortcode that is finished by </div> I got br (or br /) tag.
    trying to filter them out, but i dont know how.

    <div class="fullwidth">
       <div class="fullwidth-content">
         <div class="twocol-one"> content
         </div><br>
       </div><br>
       <div class="twocol-second"> content
       </div><br>
       <div class="clearboth"></div>
    </div><br>

    seems BR is newline from tinyMCE. And I don’t want loooong shotcode lines.

    I am trying to use str_replace OR preg_replace but i cannot create correct $pattern.

    Can you help me?

    my function

    function replace_br($content) {
    $rep = str_replace("</div><br />", "</div>", $content);
    return $rep; }
    add_filter('the_content', 'replace_br');

    not working. Probably because of white spaces between them, i think

Viewing 6 replies - 1 through 6 (of 6 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Just looking at your str replace, shouldn’t it be “</div><br>“?

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    I know I’m not addressing your tinyMCE problem but could you style the <br>s so that they’re invisible?

    Thread Starter ponco85

    (@ponco85)

    I’ve tried it. I’ve tried also
    $rep = str_replace("/div><br", "/div", $content);

    Thought about this, using CSS

    .fullwidth br {display: none;}
    OR
    .fullwidth br {display: inline;}

    but i cannot do it because i like to have some BRs in shortcode content

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    What about this:

    .fullwidth-content ~ br

    Thread Starter ponco85

    (@ponco85)

    Thanks for your interest 😉
    that’s fine for in-fullwidth BRs.
    stay’s only one – first BR after closing DIV. And another shortcodes’ after closing DIVs’ BRs

    Thread Starter ponco85

    (@ponco85)

    tried to use
    $rep = preg_replace("/\s*<br\s*\/?>/i", "",$content); in function. It replaced all BRs. (fine)
    i want to replace only BRs after closing div tag, so i expand it by </div> at the beginning and replace by </div>
    $rep = preg_replace("/<\/div>\s*<br\s*\/?>/i", "</div>",$content);
    Thats not working. WHY?

    No error returned.

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

The topic ‘strip out after’ is closed to new replies.