WordPress.org

Ready to get started?Download WordPress

Forums

Exclude images from gallery (1 post)

  1. d@nny
    Member
    Posted 1 year ago #

    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: http://codex.wordpress.org/The_WordPress_Gallery

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic