Change all occurrences of “http” to “https” on a wordpress page

后端 未结 8 1603
心在旅途
心在旅途 2021-02-04 19:33

I am in the process of implementing SSL on some of my wordpress-powered site\'s pages. Currently I\'m getting mixed content warnings on the secured pages - my custom theme inclu

8条回答
  •  天命终不由人
    2021-02-04 20:17

    if you only want to make sure there is no mixed content when an HTTPS request is made, try adding simple code snippet to the "function.php" file of the current theme.

    function _bd_force_https()
    {
        if ( empty( $_SERVER['HTTPS'] ) ) return;
        ob_start();
    }
    add_action( 'template_redirect', '_bd_force_https', 1 );
    
    function _bd_output_https_page()
    {
        if ( empty( $_SERVER['HTTPS'] ) ) return;
        echo str_ireplace( 'http://', 'https://', ob_get_clean() );
    }
    add_action( 'wp_footer', '_bd_output_https_page', 99 );
    

    PROS:

    • very lean, simple to add
    • does not use javascript/jquery

    CONS:

    • not a plugin so it will break when theme is changed
    • cannot intercept HTTP requests made by javascripts from the client side

提交回复
热议问题