WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
Do it by custom image sizes: wordpress.stackexchange.com/questions/74103/… – user1867002 Jul 11 '14 at 14:55

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


share|improve this answer
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
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';


        // 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() */
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.