Meow Apps

Media File Renamer: Code Snippets

If you wish to control the renaming, you can use the filters like mentioned in the FAQ. Here are a few code snippets you can use. Generally, this code is added in the functions.php of your theme. You could also use a plugin such as Code Snippets.

Add the upload day in front of the filename

// Override the filename naming rules with this filter
add_filter( 'mfrh_new_filename', 'my_filter_filename', 10, 3 );

function my_filter_filename( $new, $old, $post ) {
  
  // Get the date from the $post (which is the media entry) and convert it to a timestamp
  $post_date = strtotime( $post['post_date'] );
  
  // Make this timestamp to looks like 2018-01-01
  $formatted_date = date('Y-m-d', $post_date);
  
  // Add this timestamp in front of the filename already decided by Media File Renamer
  $new_filename = $formatted_date . "-" . $new;
  
  return $new_filename;
}