Where is the right place to store custom images?

WordPress has a core function wp_upload_dir that return info for the current upload folder.

Using this function you can retrieve all info on uploads folder base on current configuration.

E.g. if you set WP_CONTENT_DIR and/or WP_CONTENT_URL or UPLOADS constants that function will return the direcory according to this settings.

If you have checked the option to store media based on current month, in WordPress settings you’ll get that info too.

What I suggest is to use this function and appened the folder ‘cover’:

$upload_info = wp_upload_dir();
$covers_path = $upload_info['basedir'] . '/cover' .  $upload_info['subdir'];
$covers_url = $upload_info['baseurl'] . '/cover' .  $upload_info['subdir'];

with standard settings, the $covers_path will be something like:

/path/to/wordpress/wp-content/uploads/covers/

if you have year/month organization turned off, or it will be something like

/path/to/wordpress/wp-content/uploads/covers/2013/11

if year/month organization is turned on.

In this way:

  • Your path became dynamic instead of hardcoded, and if you have to change you settings (e.g. domain, subdomain, WP folder…), for some reason in the future, you will have no problem
  • You can make use of the year/month organization of uploaded images, that is very useful if you have a lot of images

Additionally, as @Rarst said in comment, if content is being added from inside WP on ongoing basis, content uploads is nearly only place that is as likely to be easy to write to as possible (otherwise native uploads don’t work). Pretty much any other place in WP install needs to go through filesystem API for reliable writes.

tech