WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

just starting out in WP dev, and I'm looking for any guidance I can get. What I'd like to do is use a hook or filter to add my own option to the core WP gallery shortcode. I would want it to work just like the standard 'exclude' option, but still show those images for Administrators. So it would look something like this: [gallery exclude="1" hide="2,3,4,5,6" link="file"]

So, basically I'm looking for guidance on how to create a function that would add the "hide" function to individual image id's within the gallery shortcode which would work exactly like the exclude, but those images would still show up in the frontend for administrators. Thank you for your time, and expertise.

share|improve this question
up vote 1 down vote accepted

This code should work in your functions.php

add_shortcode('gallery', 'custom_gallery_function');
function custom_gallery_function($atts) {
    $user = wp_get_current_user();

    // if current user isn't admin, add posts to be hidden to exclude
    if(!in_array('administrator', $user->roles))
        $atts['exclude'] = $atts['exclude'] . ',' . $atts['hide'];

    // call the wordpress shortcode function
    return gallery_shortcode($atts);
share|improve this answer
Works perfectly. Thank you so much for your help. – sosukeinu Oct 18 '12 at 17:10

Your Answer


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.