admin管理员组文章数量:1296897
The code on the page looks like this:
if ( ! empty( $image ) ) : ?>
<div class="headshot">
<img src="<?php echo esc_url( $image ); ?>" alt="Photo of <?php echo esc_attr( $author_name ); ?>"/>
</div>
But when the image shows up on the page it's using http instead of https like the rest of the site.
When go to the WP codex to see the usage for esc_url it shows me this under usage but I don't know the correct syntax to use to make the protocol forced to https:
<?php esc_url( $url, $protocols, $_context ); ?>
The code on the page looks like this:
if ( ! empty( $image ) ) : ?>
<div class="headshot">
<img src="<?php echo esc_url( $image ); ?>" alt="Photo of <?php echo esc_attr( $author_name ); ?>"/>
</div>
But when the image shows up on the page it's using http instead of https like the rest of the site.
When go to the WP codex to see the usage for esc_url it shows me this under usage but I don't know the correct syntax to use to make the protocol forced to https:
<?php esc_url( $url, $protocols, $_context ); ?>
Share
Improve this question
asked Jun 10, 2015 at 21:55
jimmyplaysdrumsjimmyplaysdrums
1131 silver badge7 bronze badges
4 Answers
Reset to default 2esc_url never force the URL to protocol it's only checking and escaping the passed URL from invalid characters, the $protocols variable is an array of acceptable (white list) protocols not for forcing destination URL.
// Forcing URL to https instead of http
$YOUR_URL = esc_url($YOUR_URL);
if( 'http' == parse_url($YOUR_URL, PHP_URL_SCHEME) ){
$NEW_URL = str_replace('http://', 'https://', $YOUR_URL);
}
The $protocols
parameter accepts an array, so:
$protocols = array(
'https'
);
But "https" is listed as a default so I am not sure that is the problem. My guess is that there is a filter interfering... clean_url
for example, or kses_allowed_protocols
Old thread but i had similar issue today. If you install SSL Insecure Content Fixer plugin, then go on setting once installed and select 'Capture All' and save.
This fixed the issue for me. Make sure you back up your database and site beforehand just incase something goes wrong.
The function you were looking for (but didn't land until dec 2015), is set_url_scheme
set_url_scheme( $url, 'https' ) )
Internally the function checks if is_ssl is true, will only set the url scheme if the passed url has a scheme.
本文标签: phpescurl( ) won39t use https
版权声明:本文标题:php - esc_url( ) won't use https 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741645623a2390167.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论