Home >CMS Tutorial >WordPress >What to do if css cannot be loaded after wordpress turns on ssl

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

藏色散人
藏色散人Original
2020-12-21 09:44:263298browse

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);
}

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';

But make sure your modifications are before this line

require_once(ABSPATH . 'wp-settings.php');

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!

Statement:
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