Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Use the ‘upload_dir’ filter to manage the path and ‘wp_unique_filename’ filter to manage the file name. Coordinate with the ‘wp_handle_upload’ filter which manages the data returned by the wp_handle_upload() function, which becomes the data stored in attachment meta data.

    Thread Starter bluder

    (@bluder)

    I solved this using the wp_get_attachment_metadata filter. Removed the suffixes -{$width}x{$height} for all sizes, and put the prefix at the beginning of the file name, instead in the beginning URL.

    function attachment_metadata_filter($data) {
      foreach ($data['sizes'] as $key => $size) {
        $width = $size['width'];
        $height = $size['height'];
    
        $fileNoSuffix = str_replace("-{$width}x{$height}", '', $data['sizes'][$key]['file']); // remove suffix
        $data['sizes'][$key]['file'] = "{$width}x{$height}/" . $fileNoSuffix; // add prefix
      }
    
      return $data;
    }
    add_filter('wp_get_attachment_metadata', 'attachment_metadata_filter');
    • This reply was modified 6 years, 9 months ago by bluder.
    • This reply was modified 6 years, 9 months ago by bluder.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WP filter for thumbnails suffix’ is closed to new replies.