默认WordPress自定义媒体上传路径wp-contentuploads并以年和月文件夹归档,如果想修改这个默认的存放目录,可以参考我之前的两篇文章。
方法一:通过add filter 钩子修改上传路径将下面的代码添加到当前主题functions.php文件中:
function slider_upload_dir($uploads) {
$siteurl = get_option( ‘siteurl’ );
$uploads[‘path’] = WP_CONTENT_DIR . ‘/slider’;
$uploads[‘url’] = $siteurl . ‘/wp-content/slider’;
$uploads[‘subdir’] = ”;
$uploads[‘basedir’] = $uploads[‘path’];
$uploads[‘baseurl’] = $uploads[‘url’];
$uploads[‘error’] = false;
return $uploads;
}
add_filter(‘upload_dir’, ‘slider_upload_dir’);
之后媒体上传路径会修改为: wp-content/slider,自己可以修改目录名称。需要注意的是使用该方法修改路径后,如果再次修改路径,在后台媒体库中将看不到之前上传的图片
方法二:
将下面的代码添加到当前主题functions.php文件中,就可以调出该选项
//自WordPress3.5版本始,隐藏了后台媒体设置页面的“默认上传路径和文件的完整URL地址”选项
if(get_option(‘upload_path’)==’wp-content/uploads’ || get_option(‘upload_path’)==null)
{
update_option(‘upload_path’,WP_CONTENT_DIR.’/uploads’);
}
方法三:
只需要在 WordPress 根目录中的配置文件 wp-config.php 中添加以下代码保存更新即可。
define(‘UPLOADS’,”.’/image’);
这段代码的意思是重新定义您的图像上传目录为 image,您也可以根据自己的需要来定义。正常情况,我们在 WordPress 后台上传图像它的存储目录就会变成了上述代码中的 image。不过这里还有一个问题,上传后的图像还是会按年月路径存放。所以我们还需要在到 WordPress 后台 >> 设置 >> 媒体选项 >> 在“文件上传”中去掉“以年一月目录形式组织上传内容”前面的勾并点击保存更改按钮即可。
I got what you intend, thanks for posting.Woh I am delighted to find this website through google.
https://www.droversointeru.com
Czytanie Twojego wpisu to jak podróż po malowniczym krajobrazie myśli – pełnym barw, głębi i światła! Jeśli kiedykolwiek zdecydujesz się wydać książkę, na pewno znajdziesz rzeszę wiernych czytelników!
https://knperformance.pl/emulator-zetor/
A formidable share, I just given this onto a colleague who was doing a bit of analysis on this. And he in truth purchased me breakfast because I found it for him.. smile. So let me reword that: Thnx for the deal with! But yeah Thnkx for spending the time to discuss this, I really feel strongly about it and love studying more on this topic. If possible, as you change into experience, would you thoughts updating your weblog with more particulars? It’s extremely useful for me. Massive thumb up for this weblog publish!
F*ckin’ remarkable things here. I’m very glad to see your article. Thanks a lot and i am looking forward to contact you. Will you kindly drop me a mail?
https://www.droversointeru.com
aikxb9
257jyh
I was drawn into your words immediately, not just by the ideas, but by the warmth they radiate.
v5gbp6
xbcfzd
Wow, amazing blog format! How lengthy have you ever been running a blog for? you made running a blog glance easy. The overall look of your site is great, as smartly as the content!
Krytykuj przyjaciela w cztery oczy, a chwal zawsze przy swiadkach i podwladnych. Leonardo da Vinci & Tm.
https://xmc.pl