1

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.

1

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);
}

Your Answer

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

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