• I’ve just migrated my site from the live server to my localhost (XAMPP). However, the CSS doesn’t show on my site and I receive the following errors (screenshot). It seems the base URL for the links are incorrect. My website files are located within xampp/htdocs/website-name. Any help would be greatly appreciated. Thank you

Viewing 15 replies - 1 through 15 (of 15 total)
  • Hi @gareth94 Since you say only CSS is missing, I assume rest of the content looks how it’s expected. This would mean you are simply missing files in your theme folder and not that you have misplaced them in the wrong directory. Something has gone wrong in your migration. Copy over all the files again and that should fix it.

    Thread Starter gareth94

    (@atebol)

    Thank you for your help with this Ashfame. I actually used the Duplicator plugin (the free version) to do the migration. I had to do the 2-step install as my project was over 500MB in size. So I transferred the files manually (via FTP) and then Duplicator exported the database and prepared an installer.php for me to complete the transfer. So I basically let the plugin do all the work to be honest! I haven’t had to change any of code myself.

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    If you can install plugins, install “better search replace”. Search for old.comain.com and replace with localhost.

    @gareth94 Can you go inside your theme folder and ensure those missing files in your screenshot are indeed present? If not, then re-do the manual FTP operation of copying over the files. If they are, it could be a permission issue. Since its localhost, you can set the file permissions to 755 or even 777.

    I don’t think you need string replacement as per the screenshot since the URLs are already localhost/XXXX

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    on re-reading, I agree with ashfame. šŸ™‚

    Thread Starter gareth94

    (@atebol)

    Thank you both. Like you said @ashfame my URLs are already localhost. I’ve just checked and the files are indeed present in the directories noted in the errors. Sorry, how would I go about changing the file permissions? Would I do the whole directory? Thank you

    I am going to assume you are on MacOS or linux since Windows won’t have this file permission issue.

    Ideally you want the entire WordPress files to have the right file permissions.
    Executing these 2 commands from the root of WordPress install files would do it for you:
    find . -type d -exec chmod 755 {} \;
    find . -type f -exec chmod 644 {} \;

    You can also read more on changing file permissions on command line – https://wordpress.org/support/article/changing-file-permissions/#using-the-command-line

    Thread Starter gareth94

    (@atebol)

    Thank you @ashfame. Sorry I should have mentioned, I’m actually using a Windows PC.

    In that case, I think, files are not where they are supposed to be.

    To confirm you are working with the right directory or path, create a new file in your themes folder “where.txt” with some content “I am here”.

    Then access it from browser – http://localhost/wp-content/themes/ubiquity/where.txt and see if you are able to access that fine. If yes, then you are in the right directory otherwise you might be working with a copy of files that are in use (you might have multiples?)

    Thread Starter gareth94

    (@atebol)

    Thanks @ashfame. I’ve just done that and was able to see “I am here” šŸ™‚ no errors on the console too. I did have to place my website name after localhost/ in the URL though (which makes sense?)…

    Ok, so you just need to update the site name to localhost/websitename which would make the path correct for everything the site would try to load.

    To do so, you can simply add these lines to your wp-config.php

    define( 'WP_HOME', 'http://localhost/websitename' );
    define( 'WP_SITEURL', 'http://localhost/websitename' );

    Thread Starter gareth94

    (@atebol)

    Ah this is stange… I’ve already got the URLs set up in that way:

    define( 'WP_HOME', 'http://localhost/websitename' );
    define( 'WP_SITEURL', 'http://localhost/websitename' );

    Is there something wrong with the way I have it above? I can’t spot anything obvious!?

    That looks correct. If you are able to access your site on http://localhost/websitename then the urls how they are being added to the theme is probably incorrect. See if they are hardcoded relative URLs like /wp-content/themes/ubiquity/css/styles.css

    Also in your wp-content directory, if you have any cache directory, remove it.

    Thread Starter gareth94

    (@atebol)

    Thanks @ashfame. I’ve just had a look in some of the files and a lot of the URLs begin with /wp-content/themes/ . . .. For example:

    <link rel="stylesheet" type='text/css' href="/wp-content/themes/ubiquity/css/bootstrap/css/bootstrap.min.css">

    Surely these should be fine if the base URL has been set as localhost/websitename/?

    @gareth94 That’s the issue then. Relative urls doesn’t work in respect to the site url, but relative to domain, which is why the path to css/js files are localhost/wp-content/.... without websitename in them.

    This would have worked fine, if you mapped a domain for use locally. Eg: websitename.dev

    Root cause is the code is poorly written. CSS/JS files are not meant to be hardcoded in templates like that. They should be enqueued properly, which respects the site url.

    For now, you can try to move your files one directory above, directly under localhost, without the folder/directory websitename under localhost path. Then the site would be accessible directly under localhost and urls would work fine. But this assumes you wouldn’t need any other site on your computer, otherwise you need to fix at the code level or properly loading the files – https://wordpress.org/plugins/disable-media-pages/

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘CSS not showing on localhost version of site’ is closed to new replies.