admin管理员组文章数量:1395905
On a fresh install, I want to move the upload folder to a subdomain (supposed to speed up download). My subdomain links to a folder called static. So I have:
- Home
- wp
- wp-admin
- wp-content
- wp-include
- static
- wp
Now I need to tell WordPress where the upload folder is and define its URL. The codex says I should edit wp-config to define UPLOADS relative to ABSPAHT. But if I put define( 'UPLOADS', '../static' );
of course URL in pages are like //mydomain.tld/wp/../static/image.jpg
I've looked around, and found many different answers to that (filters, DB edit,...), some of them no longer true (since the media settings page no longer allows to change the upload folder) and some obviously wrong... I want to do it the right way.
I went to the wp-admin/options.php page and set upload_path = ../static
and upload_url_path =
and that seems to work.
But is that how it's supposed to be done? And if developpers have removed these options from the media settings page, isn't there a risk that the feature is later completely removed?
On a fresh install, I want to move the upload folder to a subdomain (supposed to speed up download). My subdomain links to a folder called static. So I have:
- Home
- wp
- wp-admin
- wp-content
- wp-include
- static
- wp
Now I need to tell WordPress where the upload folder is and define its URL. The codex says I should edit wp-config to define UPLOADS relative to ABSPAHT. But if I put define( 'UPLOADS', '../static' );
of course URL in pages are like //mydomain.tld/wp/../static/image.jpg
I've looked around, and found many different answers to that (filters, DB edit,...), some of them no longer true (since the media settings page no longer allows to change the upload folder) and some obviously wrong... I want to do it the right way.
I went to the wp-admin/options.php page and set upload_path = ../static
and upload_url_path = http://static.mydomain.tld
and that seems to work.
But is that how it's supposed to be done? And if developpers have removed these options from the media settings page, isn't there a risk that the feature is later completely removed?
Share Improve this question asked Apr 3, 2016 at 16:31 MatMat 1891 gold badge3 silver badges9 bronze badges 2- Whatever the codex says is the correct way of doing things. If that doesn't suit your needs then whatever solution you can find is a workaround, and there are no right or wrong workarounds. So if it works for you for now, stick to it and just watch for changes/updates. – ed-ta Commented Apr 3, 2016 at 16:41
- 1 Sure, but that codex page only deals with upload_path, not upload_URL. And that page is only about editing wp-config, plus the whole section has a disclaimer "The following sections may contain advanced / unsupported information" which makes me wonder. – Mat Commented Apr 3, 2016 at 16:50
3 Answers
Reset to default 9I went to the wp-admin/options.php page and set ... But is that how it's supposed to be done?
Nope. You should never change anything in the WordPress core files because all your changes will be lost during the next update. You should use actions and filters instead:
add_filter( 'pre_option_upload_path', function( $upload_path ) {
return '/path/to/static';
});
add_filter( 'pre_option_upload_url_path', function( $upload_url_path ) {
return 'http://static.example';
});
I had a similar problem mapping subdomain media. Asked & Answered here.
In short, add to functions.php the following:
update_option('upload_url_path', '/wp-content/uploads');
If, for whatever reason you don't want to set the upload path options in the database or in your functions.php
, you can still set the option filters in your wp-config.php
like this (before calling any WordPress core file):
$GLOBALS['wp_filter']['pre_option_upload_path'][10][] = array(
'function' => function( $upload_path ){
return '/path/to/static';
},
'accepted_args' => 1,
);
$GLOBALS['wp_filter']['pre_option_upload_url_path'][10][] = array(
'function' => function( $upload_url_path ){
return 'http://static.example';
},
'accepted_args' => 1,
);
WP_Hook::build_preinitialized_hooks
will properly update these array items to the actually used internal format.
本文标签: Change WordPress upload path and URL
版权声明:本文标题:Change WordPress upload path and URL 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744634278a2616730.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论