Home Website Building Knowledge Standard Post

Standard Post

How to Set the Image Upload Folder for a Self-Built WordPress Website

After installing WordPress by default, the image upload folder is stored on the server in the year/month format. However, if you upload many images in a certain month, plus automatically generated thumbnails, the folder can contain tens of thousands of images, affecting server efficiency. Therefore, we need to customize the WordPress upload path. …

Posted on February 27, 2020 About 2 minutes read
自己搭建的WordPress网站怎么设置图片上传文件夹

After installing WordPress by default, uploaded images are stored on the server in a year/month folder structure. However, if many images are uploaded in a particular month, along with automatically generated thumbnails, the folder can contain tens of thousands of images, affecting server efficiency. Therefore, we need to customize the WordPress upload path.

Method 1: Customizing the WordPress Upload Folder

We can install the Custom Upload Dir plugin to achieve this.

This plugin allows you to customize the upload path.You can construct variable paths from elements like the Post title, Category, Post author, and Publication date.etc.

WordPress自定义上传路径

Download Link

Method 2: Customizing the WordPress Upload Folder

This is a plugin-free method using code. Insert the following code into your website Theme's functions.php file to upload to a specified folder.

add_filter('upload_dir', 'awesome_wallpaper_dir');

function awesome_wallpaper_dir( $param ){
    $mydir = '/awesome';

    $param['path'] = $param['path'] . $mydir;
    $param['url'] = $param['url'] . $mydir;

    return $param;
}

/awesome is the path location you set.

For details, please see: https://codex.wordpress.org/Plugin_API/Filter_Reference/upload_dir

Rate this article post
Previous SiteGround Free SSL Certificate Setup Tutorial (Applicable to New Panel) Continue reading content around the same timeline. Next SiteGround vs Bluehost, Why I Recommend SG's Servers View the next related tutorial or experience.

AI Website Building Assistant

🤖
Hello! I am the Naibabiji AI Assistant. How can I help you?
Quick Consultation: