WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Preventing default image sizes from being made (2 posts)

  1. sccr410
    Member
    Posted 1 year ago #

    I am working on a variation of a photo gallery plugin which is setting up a custom post type and some custom image sizes. The front end display of this custom post type will only ever use the custom sizes, it does not at all want anything to do with the default WordPress sizes. As such, I'd like to prevent the image generation of the thumbnail, medium and large versions which are automatically generated by WordPress on any uploaded image - but only when uploading during add/edit of the custom post type.

    Is this possible? If so, where do I start? Haven't been able to find any actions/filters to help.

  2. sccr410
    Member
    Posted 1 year ago #

    As usual, right after I post I find the solution:

    add_image_size( 'custom-thumbnail', 400, 300, true );
    add_image_size( 'custom-medium', 800, 800, false );
    
    add_filter('intermediate_image_sizes', 'change_image_sizes', 10, 1);
    function sunshine_change_image_sizes($image_sizes) {
    	if (get_post_type($_POST['post_id']) == 'my-cpt') {
    		unset($image_sizes);
    		$image_sizes[] = 'custom-thumbnail';
    		$image_sizes[] = 'custom-medium';
    	}
    	return $image_sizes;
    }

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your posted code may now have been permanently damaged/corrupted by the forum's parser.]

Topic Closed

This topic has been closed to new replies.

About this Topic