wp_thumbnail_max_side_length $file parameter (4 posts)

  1. thomastraum
    Posted 9 years ago #


    I love the new wp_thumbnail_max_side_length filter, but wondering how to get access to the $file parameter sent with it. In the admin-functions.php it says:

    $max_side = apply_filters( 'wp_thumbnail_max_side_length', 128, $attachment_id, $file );

    So I am assuming its sending $file as a parameter with but I fail to access it in my own function:

    function custom_thumbsize( $size,$attachment_id, $file )
    $th_width = 565;
    $th_height = 691;

    // figure out the longest side
    $image_attr = getimagesize( $file );
    if ( $image_attr[0] > $image_attr[1] ) {
    $th_size = $th_width;
    //width is > height
    } else if ( $image_attr[0] < $image_attr[1] ) {
    $th_size = $th_height;
    //height > width
    return $th_size;


    add_filter( "wp_thumbnail_max_side_length", "custom_thumbsize" );

    Any help greatly appreciated,



  2. Change this:
    add_filter( "wp_thumbnail_max_side_length", "custom_thumbsize" );

    To this:
    add_filter( 'wp_thumbnail_max_side_length', 'custom_thumbsize', 10, 3 );

    I think that's the issue here. The extra parameters are optional. The 10 specifies the priority (10 is the default), the 3 specifies how many parameters your function can accept (1 is the default).

  3. thomastraum
    Posted 9 years ago #

    Woohoo, that was it, thanks so much Otto42

  4. voice220
    Posted 9 years ago #

    Hi thomastraum,

    Have you made this into a plugin at all? I would be quite interested in it.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.