Search
 
SCRIPT & CODE EXAMPLE
 

PHP

rename image file using post id in wordpress programmatically

function rename_attachment($post_id, $newfilename) {
        $file = get_attached_file($post_id);
        if (!$file) {
            echo "No attachment found!";
            die();
        }
        if (!$newfilename) {
            echo "Filename is empty!";
            die();
        }
        $path = pathinfo($file);
        $newfile = $path['dirname'] . "/" . $newfilename . "." . $path['extension'];
        rename($file, $newfile);
        update_attached_file($post_id, $newfile);

        echo "attachment " . $post_id . " updated from " . $path['basename'] . " to " . $newfilename . "." . $path['extension'];
    }
Comment

PREVIOUS NEXT
Code Example
Php :: how to remove payment link in invoice woocommerce 
Php :: acf advanced link 
Php :: Comment faire en sorte que le numéro de téléphone ne soit pas un champ obligatoire dans WooCommerce 
Php :: set renew subscroption stripe update 
Php :: update php 7.2 centos 8 command line without sudo 
Php :: php artisan seading 
Php :: import facade laravel 
Php :: wp rest api remove _links 
Php :: count letters in string without space or characters and numbers in php 
Php :: codeigniter query Profiling - To disable the profiler 
Php :: js data php 
Php :: Formatting an Excel Column 
Php :: VerifyEmailController in Api 
Php :: laravel handle image validation 
Php :: requires ext-pcntl 
Php :: how to cooncet dabase eith laraavel 
Php :: how to make:trait in commend line in laravel 
Php :: Gsuite integration in Laravel PHP 
Php :: Including ACF in a custom theme or plugin 
Php :: wordpress get posts by multiple authors 
Php :: how to fetch group name in custom post type in wordpress 
Php :: Syntax error or access violation: 1072 Key column doesnt exist in table laravel migrate 
Php :: php pdo connect to database 
Php :: [name] 
Php :: strrev 
Php :: php display result from html 
Php :: comparison of two tables in laravel using model 
Php :: php get last date of month 
Php :: How can I display the data stored by summernote on laravel? 
Php :: <= in php 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =