Title: Replace in posts doesn&#8217;t work with custom file format
Last modified: February 20, 2025

---

# Replace in posts doesn’t work with custom file format

 *  [Mario](https://wordpress.org/support/users/ejamo/)
 * (@ejamo)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/replace-in-posts-doesnt-work-with-custom-file-format/)
 * Hi, I have a problem with the plugin, it renames the file correctly but does 
   not perform the replace within the posts.
   I think the problem is because I use
   a custom thumbnail format like this:
    - picture-hd.jpg (original file)
    - picture.jpg (large)
    - picture-medium.jpg (medium)
    - picture-thumbnail.jpg (thumbnail)
 * This change to the filenames is made by a function that filters ‘image_make_intermediate_size’:
   
   add_filter( ‘image_make_intermediate_size’, ‘custom_images_filename’ );
 * Your plugin was working correctly until some past version, then I don’t know 
   from which version onwards it stopped working.
   How can I pass the custom file
   format information to the plugin?Thank you very much

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Thread Starter [Mario](https://wordpress.org/support/users/ejamo/)
 * (@ejamo)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/replace-in-posts-doesnt-work-with-custom-file-format/#post-18345591)
 * no idea?
 *  Plugin Author [crossi72](https://wordpress.org/support/users/crossi72/)
 * (@crossi72)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/replace-in-posts-doesnt-work-with-custom-file-format/#post-18347916)
 * Hi [@ejamo](https://wordpress.org/support/users/ejamo/),
   I’m sorry for my late
   reply, I’ll check immediately this issue and let you know if I can release a 
   fix.
 * Thank you for reporting.
   C.
 *  Plugin Author [crossi72](https://wordpress.org/support/users/crossi72/)
 * (@crossi72)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/replace-in-posts-doesnt-work-with-custom-file-format/#post-18358921)
 * Hi [@ejamo](https://wordpress.org/support/users/ejamo/),
   I’m finally back in 
   the office, can you tell me which code are you using in the custom_images_filename
   method, so that I can replicate your issue?
 * Thank you
   C.
 *  Thread Starter [Mario](https://wordpress.org/support/users/ejamo/)
 * (@ejamo)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/replace-in-posts-doesnt-work-with-custom-file-format/#post-18358975)
 * Hi, don’t worry for delay.
   The following code create these thumbnails when we
   load a picture with “-hd” prefix, i.e. colosseum-hd.jpg
    - colosseum-hd.jpg (original file)
    - colosseum.jpg (large)
    - colosseum-medium.jpg (medium)
    - colosseum-thumbnail.jpg (thumbnail)
 *     ```wp-block-code
       add_filter( 'image_make_intermediate_size', 'custom_images_filename' );function custom_images_filename( $image ) {    // Info file    $info = pathinfo($image);    $dir = $info['dirname'] . '/';    $ext = '.' . $info['extension'];    $name = wp_basename( $image, "$ext" );    $hd= '-hd';    // If image is High Definition remove prefix    if(strpos($name,$hd) !== false) {        $name = str_replace($hd,'',$name);    // If image is Low Definition don't change filename but add '-hd' to "large" dimension    } else {        $force_prefix = 'yes';    }    // Get image information    $img = wp_get_image_editor( $image );    $img_size = $img->get_size();    // Image prefix for builtin sizes     $widths = [];    $size_based_img_name_prefix = '';    foreach ( get_intermediate_image_sizes() as $_size ) {        $width = get_option( "{$_size}_size_w" );        if ( ! isset( $widths[ $width ] ) ) {            $widths[ $width ]  = $_size;        }    }    if ( array_key_exists( $img_size[ 'width' ], $widths ) ) {        if($widths[ $img_size['width'] ]!='large' || $force_prefix=='yes') $size_based_img_name_prefix = '-'.$widths[ $img_size['width'] ];        $name_prefix = substr( $name, 0, strrpos( $name, '-' ) );    } else {        $name_prefix = $name;    }    // Build our new image name    $new_name = $dir . $name_prefix .$size_based_img_name_prefix . $ext;    // Rename the intermediate size    $did_it = rename( $image, $new_name );    // Renaming successful, return new name    if( $did_it ) {      return $new_name;    } else {      return $image;    }}
       ```
   
 * The plugin works fine with filenames without “-hd” (both in renaming them and
   in performing the replace within the content of posts) while with files containing“-
   hd” it only renames them but does not perform the replace within posts.
   Thank
   you
 *  Plugin Author [crossi72](https://wordpress.org/support/users/crossi72/)
 * (@crossi72)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/replace-in-posts-doesnt-work-with-custom-file-format/#post-18361651)
 * Hi [@ejamo](https://wordpress.org/support/users/ejamo/),
   everything worked in
   my tests, maybe the image resolution is involved, can you send me at [support@eurosoftlab.com](https://wordpress.org/support/topic/replace-in-posts-doesnt-work-with-custom-file-format/support@eurosoftlab.com?output_format=md)
   a test image that causes the issue on your server?
 * Thank you
   C.
 *  Thread Starter [Mario](https://wordpress.org/support/users/ejamo/)
 * (@ejamo)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/replace-in-posts-doesnt-work-with-custom-file-format/#post-18361734)
 * Hi, thank you for the tests you have done.
 * I don’t think it depends on the single photo, because we have tried dozens of
   them and unfortunately the problem is always the same.
 * I have to say that until a few versions ago everything was working correctly,
   so I don’t know what might have changed or if a conflict with other plugins might
   have occurred (although to be honest we use very few of them).
 * Could it be a problem related to the priority with which operations are executed?
   Any other ideas on what to investigate?
 * Thank you again

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Replace in posts doesn’t work with custom file format’ is closed to new
replies.

 * ![](https://ps.w.org/phoenix-media-rename/assets/icon-256x256.png?rev=3120623)
 * [Phoenix Media Rename](https://wordpress.org/plugins/phoenix-media-rename/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/phoenix-media-rename/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/phoenix-media-rename/)
 * [Active Topics](https://wordpress.org/support/plugin/phoenix-media-rename/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/phoenix-media-rename/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/phoenix-media-rename/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [Mario](https://wordpress.org/support/users/ejamo/)
 * Last activity: [1 year, 2 months ago](https://wordpress.org/support/topic/replace-in-posts-doesnt-work-with-custom-file-format/#post-18361734)
 * Status: not resolved