修改 wordpress 默认 上传目录

修改 wordpress 默认 上传目录

wordpress 的默认上传目录为 wp-contents/uploads/

看了下wp_upload_dir函数,应该是可以通过修改数据库表 wp_options 中的 upload_path 来实现修改的。

另一个方法是通过 add_filter 实现,要写点代码,以下代码来自 http://www.9elite.com/custom-wordpress-upload-directory/

function custom_upload_dir($uploads) {
    $subdir = '';
    if ( get_option( 'uploads_use_yearmonth_folders' ) ) {
        // Generate the yearly and monthly dirs
        if ( !$time ) $time = current_time( 'mysql' );
        $y = substr( $time, 0, 4 );
        $m = substr( $time, 5, 2 );
        $subdir = "/$y/$m";
    }
    $uploads['basedir'] = $_SERVER['DOCUMENT_ROOT'] . '/uploads';
    $uploads['baseurl'] = 'http://'. $_SERVER['SERVER_NAME'] . '/uploads';
    $uploads['path'] = $uploads['basedir'] . $subdir;
    $uploads['url'] = $uploads['baseurl'] . $subdir;
    $uploads['error'] = false;
    return $uploads;
}
add_filter('upload_dir', 'custom_upload_dir');


发表评论?

0 条评论。

发表评论