WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Trouble moving wp-content (8 posts)

  1. Joseph Jacobs
    Member
    Posted 8 months ago #

    Hey guys,

    I am having a weird problem. I am trying to move wp-content outside of the web root directory. If it makes a difference, wp-config is one level above the web root, in the same directory as wp-content. I changed these two lines in wp-config

    define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/content' );
    define( 'WP_CONTENT_URL', 'http://' . $_SERVER['HTTP_HOST'] . '/content' );

    I know WordPress has found the new directory because when I installed a new theme it was installed in the right place. But when I activated the theme, I get a bunch of 404s for the theme files. The browser tries to access http://sitename.com/content/themes/twentytwelve/style.css but gets a 404 error in return. Not sure what I did wrong. Am I missing something obvious here?

    Cheers,
    Joe

  2. Joseph Jacobs
    Member
    Posted 8 months ago #

    Ok done a bit more digging and I found this line in the codex

    Since Version 2.6, you can move the wp-content directory, which holds your themes, plugins, and uploads, outside of the WordPress application directory.

    Previously I took that to mean that I could move wp-content outside of the web root. Maybe I am wrong. Does it just mean I can move it outside the WordPress directory (e.g. if WP is running in a subdirectory) but wp-content would still have to be within the web root?

  3. martha_camellia
    Contributor Day Volunteer
    Posted 8 months ago #

    For WordPress, your wp-content does not have to be at or under the WordPress directory, but some plugins and themes hard-code the URL to wp-content (ignoring WP_CONTENT_URL and WP_CONTENT_DIR settings).

    It sounds like your particular theme may have this problem. Do you have a URL that shows the problem?

  4. Joseph Jacobs
    Member
    Posted 8 months ago #

    I am using the twentytwelve theme so I don't think this should be an issue. Unfortunately I don't have a URL to show the problem. I am working on a localhost install.

  5. martha_camellia
    Contributor Day Volunteer
    Posted 8 months ago #

    If you have a way of searching your theme and plugin files you could look for wp-content to find out if the content URL is hardcoded anywhere. And try deactivating all plugins as a test, if you haven't already. Can your browser access other files in http://sitename.com/content/themes/twentytwelve?

  6. Joseph Jacobs
    Member
    Posted 8 months ago #

    I am working on a fresh install, WP 3.5.2, no plugins. I tried accessing the stylesheet URL manually at http://example.com/content/themes/twentytwelve/style.css and get a 404 error. If the request went through WP at all then it would have shown a custom 404 page. But it didn't. So I'm guessing that means the wp-content directory still needs to be in the web root so that the web server can serve the stylesheet?

  7. martha_camellia
    Contributor Day Volunteer
    Posted 8 months ago #

    I have a site set up in the same manner as (I think) you are after:

    content is http://www.example.com/content

    WordPress code is in http://www.example com/wp

    wp-config.php is in http://www.example.com/ and includes:
    define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/content' );
    define( 'WP_CONTENT_URL', 'http://' . $_SERVER['HTTP_HOST'] . '/content' );

    index.php is in http://www.example.com/ and includes:
    require( './wp/wp-blog-header.php' );

    .htaccess is in http://www.example.com/ and is standard:
    `BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress`

    I followed Mark Jaquith's WordPress Skeleten scheme: https://github.com/markjaquith/WordPress-Skeleton

    I had to address hard-coded wp-content URLs in the theme files, the database (in post content), and also in a couple of plugins, but after that it all worked.

    Good luck!

  8. Joseph Jacobs
    Member
    Posted 8 months ago #

    Hey Martha

    Thanks very much for your help. Yes I ended up using something similar to Mark Jaquith's WP Skeleton. If anyone is wondering, yes you need wp-content to be in the web root.

    Cheers,
    Joe

Reply

You must log in to post.

About this Topic