Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

hey guys, i really need your help.

Whenever I use a gallery in wordpress and set it's columns to just 1 Wordpress automatically adds <br style="clear: both"/> after every <dl class="gallery-item">. I really need to prevent this behaviour and therefore I'd like to add a filter to my functions.php

The following to examples don't work.

add_filter( 'post_gallery', 'remove_br_gallery', 9);

function remove_br_gallery($output) {

    return preg_replace('#\<br*.?\>#is', '',  $output);

}  


add_filter( 'the_content', 'remove_br_gallery', 9);

function remove_br_gallery($output) {

    return preg_replace('#\<br*.?\>#is', '',  $output);

}

Neither does this:

return str_replace('<br style="clear: both">', '',  $output);  

Any idea how I could solve that? I just don't want to have any <br style="clear: both"/> inside of my galleries.

share|improve this question

3 Answers 3

up vote 0 down vote accepted

EDIT: you must call your filter after the shortcode is processed, giving it priority > 10, and you must match on a multiline expression.

Try this work with my installation and using the standard gallery shortag:

add_filter( 'the_content', 'remove_br_gallery', 11, 2);
function remove_br_gallery($output) {
    return preg_replace('/<br style=(.*)>/mi','',$output);
}
share|improve this answer
    
thank you, but doesn't work! If I apply that function to the_content the entire content is gone. If I apply it to post_gallery nothing happens. –  mathiregister Feb 26 '11 at 11:01
    
Try preg_replace('/'.preg_quote('<br\s+style="\s*clear\s*:\s*both[;]{0,1}\s*"[/]{0,‌​1}>', '/').'/Ui', '', $output);. –  wyrfel Feb 26 '11 at 11:39
    
thank you, doesn't work either! –  mathiregister Feb 26 '11 at 12:18
    
ok...to simplify, i usually just do this: '/\<br[^\>]*\>/' –  wyrfel Feb 26 '11 at 12:24
    
thank you it works. but only with the updated version of @keatch and the regexp of @wyrfel. Thank you both for your help. Awesome. Thank you –  mathiregister Feb 26 '11 at 12:50

Or, alternatively, you could try disabling the effect of the <br>'s via a stylesheet override, for instance:

body dl.gallery-item + br { display: none; }

share|improve this answer
    
thank you, that works fine. I'm already doing that - and I'm even using jquery to remove() the br element. I just thought there might be a way so the br's doesn't even get set. –  mathiregister Feb 26 '11 at 12:19

You can use Justin Tadlock's Cleaner Gallery plugin to get clean markup.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.