Adding option to Gallery shortcode

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:

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.

Related posts

Leave a Reply

1 comment

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