Home > CMS Tutorial > WordPress > body text

What to do if css cannot be loaded after wordpress turns on ssl

藏色散人
Release: 2020-12-21 09:44:26
Original
3250 people have browsed it

Solution to the problem that css cannot be loaded after wordpress turns on ssl: 1. Find the functions.php file and replace the "js/css" path with a relative path; 2. Add the code "if" to wp-config.php ($_SERVER['HTTP_X...)" is enough.

What to do if css cannot be loaded after wordpress turns on ssl

The operating environment of this tutorial: Windows 7 system, WordPress version 5.4.2. This method is suitable for all brands of computers.

Recommended: "WordPress Tutorial"

Solution to the problem that css cannot be loaded after wordpress turns on ssl

Method 1: Find functions.php and add the following code:

add_filter('script_loader_src', 'agnostic_script_loader_src', 20,2);
function agnostic_script_loader_src($src, $handle) {
    return preg_replace('/^(http|https):/', '', $src);
}
 
add_filter('style_loader_src', 'agnostic_style_loader_src', 20,2);
function agnostic_style_loader_src($src, $handle) {
    return preg_replace('/^(http|https):/', '', $src);
}
Copy after login

Change the js/css path to a relative path. (Related course recommendations: css video tutorial)

Method 2: Add this line to wp-config.php

if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';
Copy after login

But make sure your modifications are before this line

require_once(ABSPATH . 'wp-settings.php');
Copy after login

The above is the detailed content of What to do if css cannot be loaded after wordpress turns on ssl. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template