F
F
full-size2018-08-12 17:13:46
WordPress
full-size, 2018-08-12 17:13:46

How to finalize a function for Wordpress?

Hello!
How to improve the function of generating photos uploaded to WordPress, so that when uploading files like "20180808234302.jpg", "20180808234303.jpg", "20180808234304.jpg", etc., files of the form "20180808234302-1.jpg", " 20180808234303-2.jpg", "20180808234304-3.jpg" ? Those. numbering was added to the uploaded files. Please provide a solution.
Thank you!
The code itself:

function make_filename($filename) {
    $info = pathinfo($filename);
    $ext  = empty($info['extension']) ? '' : '.' . $info['extension'];
    return date("YmdHis") . $ext;
}
add_filter('sanitize_file_name', 'make_filename', 10);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question