我知道已经讨论了该主题,但似乎未找到解决方案。这是我的情况:我有一个wordpress网站,现在有SSL。但是,在主题资源中添加了以下内容:
wp_enqueue_script( 'spectrumwp-conditional', get_template_directory_uri() . '/js/vendor/conditional.js', array('jquery'), null, true);
Run Code Online (Sandbox Code Playgroud)
但是get_template_directory_uri()返回带有http而不是https的URL。
你能帮我解决这个问题吗?
编辑: 我添加到我的wp-config.php文件
$_SERVER['HTTPS']='on';
Run Code Online (Sandbox Code Playgroud)
指向资源的链接以https://表示,例如
https://www.exaple.com/wp-content/plugins/ ...
我有
https://www.example.com/plugins/LayerSlider/ ...
例如,wp-content文件夹丢失
最终更新:
不加注释
define('FORCE_SSL_ADMIN', true);
Run Code Online (Sandbox Code Playgroud)
并添加
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
{ $_SERVER['HTTPS']='on'; }
Run Code Online (Sandbox Code Playgroud)
就在行前
/* That's all, stop editing! Happy blogging. */
Run Code Online (Sandbox Code Playgroud)
解决了这个问题!仅,我建议不要使用$ _SERVER ['HTTP_X_FORWARDED_PROTO'],因为它可能不够准确。
解决了!
您需要使用 is_ssl() 来检查站点是否正在运行 https:// 或 http://
这是检查和重定向的钩子:
function check_if_https() {
if ( !is_ssl() ) {
wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301 );
exit();
}
}
add_action ( 'template_redirect', 'check_if_https', 1 );
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5095 次 |
| 最近记录: |