Tag Archives: Wordpress

WordPress: Get path to uploads folders

Working with other people’s code can be quite frustrating at times, because coders, even the best, sometimes make unwarranted assumptions.

Among these assumptions are the locations of certain folders. Often people will hard-code a path wp-content. While this is a convention, this is not a universal. This value can be changed, and many do simply as a small added defense against bots.

Along these lines is also hard-coding a path to the uploads folder.

WordPress allows us to access the path programatically using wp_upload_dir() as such

$path = wp_upload_dir();
echo $path['url'];

Sometimes, though, one doesn’t necessarily want that extra line. I prefer to keep a minimum of code in my templates, when possible. Here’s my small little work-around. Just copy and paste the following code into you functions.php file, or where ever you please.

Call it as such get_uploads_dir('baseurl');

See in-line comments for a reminder of which path you would like it to return.

function get_uploads_dir( $arg ) {
	 * A small utility to make these paths available in a one-liner
	 * [path]   => /home/example.com/wordpress/wpcontent/uploads/2008/11
	 * [url]    => http://www.example.com/wordpress/wp-content/uploads/2008/11
	 * [subdir] => /2008/11
	 * [basedir]=> /home/example.com/wordpress/wp-content/uploads
	 * [baseurl]=> http://www.example.com/wordpress/wp-content/uploads
	 * [error]  =>
	 * */
	$image_path = wp_upload_dir();
	switch ( $arg ) {
		case 'path':
			$str = $image_path['path'];
		case 'url':
			$str = $image_path['url'];
		case 'subdir':
			$str = $image_path['subdir'];
		case 'basedir':
			$str = $image_path['basedir'];;
		case 'baseurl':
			$str = $image_path['baseurl'];
			$str = '';

	return $str;

For more details on wp_upload_dir();


Updated BlogCFC2WordPress to be compatible with WP 3.5

From the original BlogCFC2Wordpress utility:

This utility will migrate your data from a BlogCFC db into an existing WordPress 2.0 db. It has been tested on CFMX7 and BlueDragon 6.2 running on Windows against a MySQL 4 db and BlogCFC v. 3.8. The schema for v.5 of BlogCFC has some new fields added but it doesn’t look significantly different so it will probably work with minor modification. All the logic is contained in cfc’s and there is no funky sql syntax or stored procs so it should work with other databases.

This is an update to the above utility that will migrate your BlogCFC database to WordPress 3.5+

Download the WordPress 3.5 compatible version here.

Download the WordPress 2.0 compatible version here.

Thank you to Sean Tierney from Grid7.com for writing it, and of course to Ray Camden for BlogCFC and to the WordPress team.