Quantcast
Channel: Crunchify
Viewing all articles
Browse latest Browse all 1037

WordPress: How to Create a Directory within the Uploads Folder

$
0
0

WordPress-directory-structure - Crunchify Tips

When developing a plugin or theme, it can be useful to be able to programmatically create a directory within the wp-content/uploads folder. Here is a handy piece of code to do it.

Open functions.php file and add below snippet.

function myplugin_activate() {

    $upload = wp_upload_dir();
    $upload_dir = $upload['basedir'];
    $upload_dir = $upload_dir . '/mypluginfiles';
    if (! is_dir($upload_dir)) {
       mkdir( $upload_dir, 0700 );
    }
}

register_activation_hook( __FILE__, 'myplugin_activate' );

More WordPress tutorials.

The post WordPress: How to Create a Directory within the Uploads Folder appeared first on Crunchify.


Viewing all articles
Browse latest Browse all 1037

Trending Articles