• I can change the ‘Full URL path to files’ (seen in Settings/Media) using the following in functions.php, but although the path is correctly displayed in the Media page it doesn’t actually work:

    $path = get_bloginfo('template_directory');
    $path = $path . '/images';
    update_option (upload_url_path , $path );

    The only way to change the upload folder and get it working is by using a relative path (seen on the same page ‘Store uploads in this folder’) by using update_option (upload_path , $path ); in functions.php.

    However, I know of no way to get the relative path accurately and consistently either using WP functions or PHP functions (e.g. if sites are set up on subdomains). There is a lot of messy regex and hacky code around but I don’t trust any of it to be rock-solid.

    Any idea why the full path doesn’t work in ‘Full URL path to files’, or how to accurately get the relative path e.g. to the theme directory?

    For a theme I want to release.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Purab

    (@wordpressapi)

    the only issue with your code is concatenation of variable.
    use following code.

    $path = get_bloginfo('template_directory');
    $path = .$path . '/images';
    update_option (upload_url_path , $path );
    Thread Starter richarduk

    (@richarduk)

    Thanks for trying, but the extra full stop you put in throws up a syntax error that crashes the page.

    At issue is the fact that my code correctly enters the full file path that I want into Settings / Media / ‘Full URL path to files’ but that this has no effect on changing the default upload folder, whilst on the other hand I can’t find a foolproof way of entering a relative url into the input box above that (‘Store uploads in this folder’) which I know WILL change the default upload folder.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Changing upload folder using update_option’ is closed to new replies.