1

What would be a best practice to apply within WordPress to use in the event that I would need to rename an image and have it automatically renamed every where else too (i.e. on all posts and pages that make reference to this image).

What should I do, what should I avoid doing, in order to complete this objective.

Thanks

1 Answer 1

0

I did the same thing few days back. I took the post slug as image name for SEO purpose. I created a function to create/move images to a particular folder depending on the slug and input image url.

Here is look of my function-

function tb_get_image($image_ext_url,$slug,$upload_folder="",$title=''){
  $uri =  WP_CONTENT_DIR."/uploads/".$upload_folder;
  $folder =  WP_CONTENT_URL."/uploads/".$upload_folder;  

  if(!file_exists($uri)){
     $oldmask = umask(0);
     if(!mkdir ($uri, 0755)){
        $uri =  WP_CONTENT_DIR."/uploads/";
        $folder =  WP_CONTENT_URL."/uploads/";   
      }
  }


  $localimage = $uri.$slug.".jpg"; ## Use PHP_PATHINFO to get extension.
  $image = $folder.$slug.".jpg"; ## Use PHP_PATHINFO to get extension.

....

More code to rename and move/copy the image...
....
}

Hope this guide is enough to get you in right direction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.