So, I added a custom.css file in my wordpress root, now I'm wondering if it will be deleted on the next core update. Is it safe to just leave it there? Can I also create custom folders and files inside other wordpress folders like wp-content?
3 Answers
To answer your question directly. No the files won't get deleted when WordPress is updated. They will remain intact.
Taken from this link there are several other options for adding your own CSS, if you don't want to put it in the theme:
- Use Theme Options and paste in CSS
- Use a plugin to insert CSS/JS. You could also write your own plugin to 'host' the CSS file neatly in wp-content/plugins/ somewhere.
- Use a child theme, which will maintain your changes if your theme changes.
More info on each of these is in the link
Yes, those custom folders and files go inside the theme you're using. Wordpress groups files like HTML and CSS together in themes. What you should do is pop this CSS file in the directory of the theme you're using, and link to it there. Then it will definitely never get deleted, and then you have your own theme that you can apply to any Wordpress website.
So if your theme is called 'Nice Theme', you'll find a directory something like:
wp-content/themes/nice-theme
If there is a css directory in there, put your CSS in there, otherwise put it where it looks like it makes most sense, and update the point you refer to the CSS to include the extra part of the URL, e.g. if before the URL you used to load your CSS was:
https://yoursite.com/mycss.css
Then now it should be:
https://yoursite.com/wp-content/themes/nice-theme/mycss.css
-
You should not be adding files to the theme directory. They will be erased if/when the theme is updated. Exactly what they were trying to avoid. Commented Jun 16, 2020 at 13:09
-
I don't want to put files inside the theme directory. I'm asking if I can put them in the root directory and inside the wp-content folder.– 023023Commented Jun 16, 2020 at 18:40
-
@023023 You can put the file wherever you want. The question is only what location works best for the way Wordpress works and what you're doing. My suggestion is to make your own theme and put the CSS in there as that is a good place, but there are many ways to do it. I'll write another answer with some other options– mozbozCommented Jun 16, 2020 at 20:14
-
I created a must-use plugin as a replacement for functions.php, but instead of using the CSS inside of it, I'm using a css import, here's why I needed to know my custom css file would be overridden upon an update, the file is inside the root folder, but I also have a custom folder in the root and a custom folder inside wp-content.– 023023Commented Jun 16, 2020 at 21:45