LocalHost Wordpress sites not loading css after Ap

2019-08-18 17:06发布

问题:

After Upgrading to High Sierra my localhost no longer worked. I followed a number of tutorials and finally got it to work but now my Wordpress sites load but do not load the CSS and Javascript files. When I check inspector it shows that it can not load the files because the directory is wrong. The address bar says localhost/Site-Name but the files are trying to be loaded from localhost/~paul/Site-Name so I must have messed up the configuration somehow.. Hopefully somebody can help. Thanks

回答1:

Try calling your css file in the header.php like this:

<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>[path to your css from project root]/your-css.css">

I had a similar problem and using get_template_directory_uri() allowed me to solve the it because in that case, the path given in Wordpress gets the files from the root directory.

What happens if you echo this get_template_directory_uri() , it's supposed to show you the template dir something like:

localhost/wp-content/themes/[your theme]


回答2:

I found a workaround which while it does not fix my localhost not showing the Sites folder at localhost/~paul it does allow my Wordpress sites to work. I created a folder within my sites folder called ~paul and then moved all my sites into that. Now the CSS JS etc all load fine and I am happy with that.