Rename blog image filenames to numbers


My wife said she was going to write a blog, so I thought about the future and made it into WordPress.

When I uploaded an image on the newly created WordPress blog after installing WordPress 3.01 after a long time, the Korean file name went up as it is, and WordPress automatically created 3 thumbnails, but all the Korean file names were broken.

That said, every time I upload an image, I can't tell you to change it to English if it's a Korean image file.

My blog is also WordPress, but I do not upload images directly to WordPress. zenphoto Upload it through an open-source image tool called , and copy and paste it into WordPress. Now, WordPress has a built-in tool to manage media, but a few years ago there was no such thing, so I had to use a plugin, but I just used a program called zenphoto.

I had the same problem with the file name at this time as well.

I don't know if the image file name is also important when a search engine searches, but especially in the case of a Korean file name, depending on the browser's settings, it is sometimes not visible.

 

wordpress media library

 

So the idea is that when you upload an image, the program automatically renames the file to a numeric file name. The computer automatically changes it to whatever it is convenient to process, and I just have to give it a separate meaning.

I added a simple source code that renames the file to a number when the image is uploaded.

Requirements for uploading images in WordPress

When uploading an image file in wordpress, I would like it to look like the following.

1. The file name is automatically replaced with a unique numeric file name.

If the file name is a random number in addition to the year, date, and time, it will be a unique value, and it is possible to know when it was uploaded.

2. The title of the image information in the media library contains the original file name.

3. Thumbnail files automatically created by WordPress are converted into numeric files

How to automatically change filenames to numbers when uploading image files in WordPress 3.0

After searching for a while, I couldn't find any plugins or methods for word processing that do this. So I looked into the WordPress admin source code and found a place to upload the file.

Add the part in bold as below, and comment out the original $filename.

in wordpress\wp-admin\includes\file.php file

Find function wp_handle_upload and add the source code below.

srand(time());
$random = (rand()%1000);
$filename = date(“ymdHis”) . $random . substr($file['name'],-4);

Just add it between the gray codes inside the function.

// A writable uploads dir will pass this test. Again, there's no point overriding this one.
if ( ! ( ( $uploads = wp_upload_dir($time) ) && false === $uploads['error'] ) )

return call_user_func($upload_error_handler, $file, $uploads['error'] );

// add new
srand(time());
$random = (rand()%1000);
$filename = date(“ymdHis”) . $random . substr($file['name'],-4);

// comment this out $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );

// Move the file to the uploads dir

$new_file = $uploads['path'] . “/$filename”;

if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) )

return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) );

I've only seen it for a while, so I don't know if there are other problems other than this part, but I've recorded as much as I've seen.

I changed only the name in the place where I uploaded the file, but for the rest, WordPress automatically creates a thumbnail with the changed name in the thumbnail creation part, and when managing files in the media library, the title contains the original file name, not the number file. .

If you change the WordPress admin source code like this, you have to change it every time you update WordPress.

Check the number of hits on the WordPress admin screenIn the case of , when the WordPress source code is updated, the structure and implementation method of the admin source code have changed several times, so there is the inconvenience of having to find a method again when it is updated.

Still, when my wife uploaded an image file, I was able to upload it without changing the Korean file name to English.

Renaming a file to a number has a different meaning to search engines. Instead, search engines can find it well, and it is good to write down the meaning of the image in the description of the image, which is useful even when the visually impaired see it, or when the image appears late or the image disappears.

Should I still do the image file uploaded by the user? Or is it better, like me, to drop the semantics, make it easier for the computer to process, and give the user the original image filename for what they see?

In the case of simply writing the file name, the Korean file name is sometimes invisible depending on the encoding option of the user's browser, sometimes there is a space in the file name, and you have to pay attention to the file name.

In the case of Flickr, like me, the file name is made with a unique number, and the original file name is included in the title.

I'm still not sure what the answer is, but I seem to prefer this method when uploading images for blogging.







Recommendations





0 If you like the article, please click the heart~ It will be a strength to bloggers (SNS/login/advertising is not related)



Articles you might like







Health to Calendar

Import your Apple health records into your calendar events and view your health records chronologically on your calendar












Add a Comment

Email addresses are not disclosed. Required items *is indicated by

























This posting is part of Coupang Partners' activities, and a certain amount of commission is provided accordingly.