WordPress custom Upload path and URL of the generated file tutorial

Source: Internet
Author: User
Tags file url

For versions later than WordPress 3.5, the setting of the page Upload path (upload_path) and file URL (upload_url_path) for Media in the background is hidden, as shown in the following figure. Some friends need this function, so what should we do? Here we will introduce two methods to retrieve this function.

Code Retrieval

Add the following code to functions. php to restore the function:

// Retrieve Upload settings
If (get_option ('upload _ path') = 'WP-content/uploads' | get_option ('upload _ path') = null ){
Update_option ('upload _ path', WP_CONTENT_DIR. '/uploads ');
}
Options. php

Access http: // site_url/wp-admin/options. php directly, find the following options and set them as the required parameters.

You can also directly use the program. You can add the following code to funtions. php:

Add the following code to the last of the topic's functions. php?> Front:

Add_filter ('upload _ dir', 'wpjam _ custom_upload_dir ');
Function wpjam_custom_upload_dir ($ uploads ){
$ Upload_path = '';
$ Upload_url_path = '';
 
If (empty ($ upload_path) | 'WP-content/uploads' ===$ upload_path ){
$ Uploads ['basedir'] = WP_CONTENT_DIR. '/uploads ';
} Elseif (0! = Strpos ($ upload_path, ABSPATH )){
$ Uploads ['basedir'] = path_join (ABSPATH, $ upload_path );
} Else {
$ Uploads ['basedir'] = $ upload_path;
 }
 
$ Uploads ['path'] = $ uploads ['basedir']. $ uploads ['subdir'];
 
If ($ upload_url_path ){
$ Uploads ['baseurl'] = $ upload_url_path;
$ Uploads ['URL'] = $ uploads ['baseurl']. $ uploads ['subdir'];
 }
Return $ uploads;
}

Modify $ upload_path and $ upload_url_path in rows 3rd and 4, for example

$ Upload_path = 'IMG ';
$ Upload_url_path = 'http: // www.111cn.net ';

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.