1

Without using timthumb, does anyone know of a way to set jpeg_quality for certain post-types or posts?

1

You can hook into the jpeg_quality filter and do a check for the post type you want to apply the filter to.

add_filter( 'jpeg_quality', 'my_jpeq_quality' );
function my_jpeg_quality( $quality ) { 
if ((isset($_GET['post_type']) && $_GET['post_type'] == 'your_post_type') || (isset($post_type) && $post_type == 'your_post_type')) :

return 100;  //Set quality here

endif;

 }
  • hmmm... this code works, however all images that aren't 'your_post_type' are now being generated with extremely low quality. (a 444k image is now 4k!) I tried adding an "else return 90" but this seems to get ignored... ` add_filter( 'jpeg_quality', 'my_jpeq_quality' ); function my_jpeg_quality( $quality ) { if ((isset($_GET['post_type']) && $_GET['post_type'] == 'work') || (isset($post_type) && $post_type == 'work')) { return 100; //Set quality }else return 90; } – Lane Feb 14 '12 at 5:28
0
add_filter( 'jpeg_quality', 'wpse_39179_jpeg_quality_for_post_type' );

function wpse_39179_jpeg_quality_for_post_type( $quality ) {

    if ( ( isset($_GET['post_type'] ) && $_GET['post_type'] == 'post_type_slug' ) || ( isset( $post_type ) && $post_type == 'post_type_slug' ) ){

        // For this post type, we want 100% quality
        return '100';

    }else{

        // Otherwise, revert back to what was passed into this filter to allow us to modify it elsewhere
        return $quality;

    }

}/* wpse_39179_jpeg_quality_for_post_type() */

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.