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.

I'm trying to re-format the gallery output a bit, change default columns and link setting, as well as exclude the featured image from the gallery images.

I can use *add_filter('post_gallery' ...)* in functions.php but that seems to overwrite any previous calls to this filter by the core and plugins.

Example of this overwriting as requested by m0r7if3r:

function test1($content, $attr) { return $content.'Test One ';}
add_filter('post_gallery', 'test1', 10, 2);
function test2($content, $attr) { return $content.'Test Two ';}
add_filter('post_gallery', 'test2', 10, 2);

Instead of outputting the original gallery and appending 'Test One' to the output, the first function there just outputs 'Test One' on it's own. Interesting if I apply a second function as above, 'Test One Test Two' is outputted.. weird I think! Any idea why?

Alternatively I can *remove_shortcode('gallery', 'gallery_shortcode')* and add my own, but then this also removes any manipulation by other scripts/plugins.

Note: there seems to be a future solution here where a *post_gallery_output* filter has been suggested, but no idea when this will be added to the core. I'm not familiar with how and when patches like the one suggested get added, so more info about that would also be helpful.

So... any ideas how I can achieve this now? Primarily my main issue is the removal of the featured image. I can filter the content to change the gallery column and link type for now.

Thanks! Ben

share|improve this question
    
add_filter should not be overwriting other calls to that filter, can you post your code for that? –  m0r7if3r Feb 2 '12 at 13:17
    
Ok, I'll recheck and test, and post back. Thanks! –  Mere Development Feb 2 '12 at 17:03
    
I've added an example of the overwriting I mentioned in the post. –  Mere Development Feb 2 '12 at 18:14
add comment

1 Answer

up vote 1 down vote accepted

Add filter is not intended to replace fully the existing code, but rather to append it. In the case of post_gallery, if you return ANYTHING but '', it will not do ANY of the default action. If you look on line 767 of /wp-includes/media.php, you can see where the hook is applied and work around that. Depending on how much you want to do, gallery_style can be used to just add CSS to the default...if you want to do more than that, you'll have to write an entirely new output.

share|improve this answer
    
Ah ok. That's a pain. I'll have to recreate it then I guess, and make the changes in the copied original function. Lets hope the 'post_gallery_output' filter does get adopted soon :) - Thanks a lot for the info! –  Mere Development Feb 3 '12 at 0:23
add comment

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.