删除http:
和https:
从所有链接中,使用以下脚本:
add_action( \'plugins_loaded\', \'wpse_232287_init\' );
function wpse_232287_init() { // Initiate the function
ob_start( \'wpse_232287_remove_http\' );
}
function wpse_232287_remove_http( $buffer ) {
// Check for a Content-Type header, only apply rewriting to "text/html" or undefined
$headers = headers_list();
$content_type = null;
foreach ( $headers as $header ) {
if (strpos( strtolower( $header ), \'content-type:\' ) === 0 ) {
$pieces = explode( \':\', strtolower( $header ) );
$content_type = trim( $pieces[1] );
break;
}
}
if ( is_null( $content_type ) || substr( $content_type, 0, 9 ) === \'text/html\' ) { // Replace \'href\'/\'src\' attributes within script/link/base/img tags with \'//\'
$return = preg_replace( "/(<(script|link|base|img|form)([^>]*)(href|src|action)=[\\"\'])https?:\\\\/\\\\//i", "$1//", $buffer );
if ( $return ) { // On regex error, skip overwriting content
$buffer = $return;
}
}
return $buffer;
}