0

I want to completely stop echoing gallery inside the_content() because I am showing it in different position outside content as per design (with a help of get_post_gallery_images()). It is a custom theme from scratch, there are almost no plugins yet installed, I have tried it with this, but it does nothing.

 add_filter('post_gallery', '__return_false', 999);

This only works partially, if I return empty string it still shows gallery, but if I return some string it shows that instead.

add_filter('post_gallery', 'test', 999999);
function test() {
    return ''; // Shows gallery
    return 'asdfasdf'; // Doesn't show gallery but outputs this string
}
  • 2
    So why don't you return <!-- Here be dragons. --> instead? – fuxia Jan 13 at 10:15
  • @IvanTopić Note the none-strict comparison in $output = apply_filters( 'post_gallery', '', $attr, $instance ); if ( $output != '' ) { return $output; }, so false != '' is false, that's why your __return_false will not work but the suggestion from @fuxia will work.. – birgire Jan 13 at 10:26
  • Thank you it works. I didn't even thought about returning a comment, nice hack – Ivan Topić Jan 13 at 10:41
  • Actually, I just noticed... This also removes the gallery I want to show in different place, because now get_post_gallery_images() doesn't return anything -.- – Ivan Topić Jan 13 at 21:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.