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

后端 未结 8 1494
心在旅途
心在旅途 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:35

    It is better to change the legacy URLs in database level, IMHO. To replace all http:// occurrences with protocol-agnostic //, run these SQLs:

    UPDATE wp_posts 
    SET    post_content = ( Replace (post_content, 'src="http://', 'src="//') )
    WHERE  Instr(post_content, 'jpeg') > 0 
            OR Instr(post_content, 'jpg') > 0 
            OR Instr(post_content, 'gif') > 0 
            OR Instr(post_content, 'png') > 0;
    

    For single-quoted occurrences:

    UPDATE wp_posts 
    SET   post_content = ( Replace (post_content, "src='http://", "src='//") )
    WHERE  Instr(post_content, 'jpeg') > 0 
            OR Instr(post_content, 'jpg') > 0 
            OR Instr(post_content, 'gif') > 0 
            OR Instr(post_content, 'png') > 0;
    

    For more, check here

提交回复
热议问题