Support » Plugins » Hacks » Exclude images from gallery

  • On my posts i have some single images and one gallery. Now i dont want those single images to show up inside my gallery.

    Also my featured images showed up inside my gallery but fixed this with this code in my functions.php:

    function exclude_thumbnail_from_gallery($null, $attr)
        if (!$thumbnail_ID = get_post_thumbnail_id())
            return $null;
        remove_filter('post_gallery', 'exclude_thumbnail_from_gallery');
        if (!isset($attr['exclude']) || empty($attr['exclude']))
            $attr['exclude'] = array($thumbnail_ID);
        elseif (is_array($attr['exclude']))
            $attr['exclude'][] = $thumbnail_ID;
        $gallery = gallery_shortcode($attr);
        add_filter('post_gallery', 'exclude_thumbnail_from_gallery', 10, 2);
        return $gallery;
    	add_filter('post_gallery', 'exclude_thumbnail_from_gallery', 10, 2);

    I know that you can exclude images by getting the image ID and changing the gallery shortcode like you can find here:

    But i want to automatic exclude all images that are already showing up on the page as a single image. Like i did with the featered images

    Any ideas?

  • The topic ‘Exclude images from gallery’ is closed to new replies.