How to add custom css file in theme?
Some themes ask you not to edit the style.css file, instead use custom.css file. If you write code on custom.css, it will overwrite the same element style in style.css. I think this is done in order to prevent the loss of user styles on theme update, is it so? How this works? Do they already include custom.css file in their theme? But how this file is included in the theme so that he theme look for style in custom.css first? Thanks.
If the person asking this question is German then nearly certainly «overwrite» means «override». I assume the question is not saying that putting code in the custom.css file will cause the style.css file to be modified. I am not saying this to be critical, I am saying that I am confused and this is my understanding.
10 Answers 10
I usually add this piece of code if I want to add another css file
/css/my_custom_css.css" type="text/css" media="screen" />
I believe the theme makers want to retain as much as possible of the theme’s layout design. So a custom css file doesn’t hurt much. I think it’s more of a support question. With custom css file, the makers can help those who use their themes more easier. Because the original style.css is unaltered, so the theme maker can probably take a look in the custom css file.
@Kangarooo see the answer provided by Fil Joseph: Enqueue the scripts/styles you want included in the header or footer
With HTTP/1 it’s best practice to pack all basic styles into one minimized file, instead of adding another CSS file the browser needs to download and process.
Using @import in WordPress for adding custom css is no longer the best practice, yet you can do it with that method.
the best practice is using the function wp_enqueue_style() in functions.php.
wp_enqueue_style ('theme-style', get_template_directory_uri().'/css/style.css'); wp_enqueue_style ('my-style', get_template_directory_uri().'/css/mystyle.css', array('theme-style'));
I understand the path part, but what about the first part, the ‘theme-style’ and ‘my-style’ part, can I put anything in there? And what about in the functions.php what is the total code to get this working?
Activate the child theme and add the following example code in the function.php
add_action( 'wp_enqueue_scripts', 'child_enqueue_styles'); function child_enqueue_styles() < wp_enqueue_style( 'reset-style', get_template_directory_uri() . '/css/reset.css', array()); >
My proposal would be to use child themes. It is very easy to implement and all modifications you do (including styles) are completely isolated from the original theme.
To prevent overwritting of main theme CSS or other files, you should ALWAYS use a child theme in WordPress . not doing so will only cause you major headaches and problems down the road.
. and with how easy it is to setup a child theme, there is no reason you shouldn’t be using one.
Using a child theme will then allow you to override any of the main parent theme files you want, simply by copying from parent into your child, or by creating a new file with the same name.
Regarding the custom.css file there’s numerous ways that theme developers handle this . a lot of them do this simply to try and prevent clients who don’t want to use a child theme, from editing the main style.css file .
Either way you shouldn’t be worried about that, as long as you use a child theme you shouldn’t have to worry about updating your theme later on and losing your changes . get in the habit of always using child themes, you will thank me later, i promise.
Disable SSL / HTTPS for wordpress
I’ve installed WordPress and setup the database.
I go to the address and the setup page is there, but no CSS.
I think: something’s wrong, but if I just do the setup maybe everything will just go back to normal.
No.
So then I spend a while looking through search results for WordPress styles not working etc.
I discover that all the links are present in the head of the page(s), and they point to the right pages, but they are not being loaded.
WordPress is trying to use a secure connection, but I don’t have an SSL certificate or anything like that and I shouldn’t think I’ll need one for this either. This means that all the links to stylesheets and scripts are seen as untrustworthy and blocked.
I changed my searches to point in the direction of disabling https / ssl, but nothing I have found works.
E.g. I’ve tried adding stuff to my .htaccess file (lost the link to another related question on this site)
I’ve tried to find lines like define( ‘force_SSL’, true ); in wp-config.php but to no avail (related question). I’ve tried adding these lines (switching them to false) as well.
Thanks for any help. Solution: The problem was not what I thought it was. Dataplicity (I am running off a pi) forces use of HTTPS, but as wordpress wasn’t using HTTPS, the ‘insecure’ scripts weren’t being loaded. All I needed to do was enable HTTPS. I’m sure the answers below would have helped if my problem was what I thought it was, and I hope they’ll help others with the same problem as I thought I had.
You should use HTTPS, not doing so is insecure, and has poor SEO and page speed penalties. Also, can you post your answer as an answer?
When using https, wordpress doesn’t use https for CSS and JS, and admin doesn’t work. How do I fix this?
So I recently, built and LAMP server and installed wordpress on it. I connected it to the web via a reverse ssh tunnel using serveo.net. I decided to add ssl and the rest of the website seem to work fine, but wordpress keeps breaking when I try to use ssl. I went to the general settings and changed the urls to http instead of https, but when I load the pages, in the source code the css and js urls are using http instead of https, so they won’t load. Then wp-admin part won’t even load. How do I fix this? I’ve looked at quite a few posts about people having similar problems, but none of them helped.
I am very much new to wordpress development. I was about to add ssl ceritificate and for that went to General settings and add the https and removed http and saved it. After that i am not even able to login into wordpress admin. Please help me out ASAP
@ashutoshbatta If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. — From Review
4 Answers 4
- in the wp-options table, the site URLs (in two places) should be the full URL, as in https://www.example.com .
- check the site’s htaccess file for proper rewrite of http to https.
For a htaccess rule, this one works in most case:
RewriteEngine On RewriteCond % !=on RewriteRule ^(.*)$ https://%% [L,R=301]
Then look at your theme files to ensure that any references to CSS/JS include the https protocol, not http. Most well-written themes will use relative rather than absolute references to files to include.
It’s also possible a plugin might be specifying http rather than https.
Use the Network tab in Developer Tools (usually F12 in your browser) to look at each request to see where it is coming from. If the request is to a plugin folder, then check the code in there.
If I look at the page source on my test (hosted) site with the 2019 theme, the href for those statements includes the https: protocol. And I have the htaccess shown in my answer. And my wp-options table contains example.com , not just www.example.com . Perhaps yours is not set up that way?
There’s not enough space in the comments for the source but this is the link for the page jtjumper.serveo.net/wp my wp-options table has both, which are both https
Disable all your plugins (especially really simple ssl). Then set your htaccess as shown. Then run a search/replace plugin (I like «Better Search and Replace») and search for yourdomain.com and replace it with yourdomain.com .
The search-replace string mentioned in the comment above should say: search for http://yourdomain.com and replace it with https://yourdomain.com — because of formatting, it id not show correctly in the comment.
This answer solves most of the issues and I’m hoping you’ve gone through it.
The reason, I found, for HTTPS (SSL) not working on my WordPress even after changing
1. Virtual Host File aka .conf file inside /ect/apache2/sites-available
2. wp-config file inside /var/www//
3. [For AWS EC2 Users] Adding a load balancer with a SSL certificate for HTTPS connections
If after doing all this, you can view your website w/o CSS and JS working, then,
- Inside your WordPress Dashboard, go to Settings>General Under, WordPress Address (URL) add, https://.com
Under, Site Address (URL) add, https://.com
I found that, when only Site Address (URL) has been activated with the website URL, WordPress Themes automatically direct towards, the css files with HTTPS aka, https:///css/index.css .
Only your domain has SSL access hence, adding your domain name at WordPress Address (URL) solved the problems for me.
Add this code to wp-config.php in your wordpress root folder.
Also, in General Settings on the Admin Panel, change http to https for your siteurl an home.
define('FORCE_SSL_ADMIN', true); if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) $_SERVER['HTTPS']='on';
I had the same issue when I hosted my site on Azure webapp service Linux.
Try this plugin. take care when it active it works. https://wordpress.org/plugins/jsm-force-ssl/
This plugin uses native WordPress filters, instead of PHP’s output buffer, for maximum reliability, performance and caching compatibility (this plugin does not affect caching performance), along with 301 permanent redirects for best SEO (301 redirects are considered best for SEO when moving from HTTP to HTTPS).
Honors proxy / load-balancing variables for large hosting environments:
HTTP_X_FORWARDED_PROTO HTTP_X_FORWARDED_SSL Requirements:
Your web server must be configured with an SSL certificate and able to handle HTTPS request. 😉
Simply activate the plugin and you’re done:
There are no plugin settings to adjust, and no changes are made to your WordPress configuration — simply activate or deactivate the plugin to enable / disable the filters and dynamic redirects.
Как изменить ссылки css с http на https — wordpress?
вопрос в том как мне переписать ссылки на css файлы во всех файлах?
Простой 1 комментарий
а что такое HTTPS_HOST и откуда он взялся? я знаю, например, только HTTP_HOST.
напишите где-нибудь echo $_SERVER[‘HTTPS_HOST’];
что выводит?
з.ы. и вообще после прочтения Вашего вопроса возникает куча вопросов.
Открыть каждую css в редакторе и заменой. Для этого и существует относительный путь . /image/image.png
Зачем в конфиге — когда в основных настройках https вписывать надо?
Вообще работы на полчаса — при правильном подходе с заменой всех http вхождений и правильной замене сериализованных данных в БД.
В гугле написано много толковых руководств. Я не про те которые советуют припарить really ssl и прочей ерундой которая лишь маскирует и вешает дополнительный слой проверок на лету
Владимир Дружаев есть плагин изменяющий вхождения. он что-то поменял но как раз те пути css не изменил так и осталось http. я и сам знаю что меняется в базе данных, в таблице wp-option но а дальше что? все css так и остаются с http. я не прошу указать что можно найти в гугле(я думаете не искал), я прошу подсказать ответ