My site requires the use of https for all img src HTML.
This is the WordPress function I’m using to display images:
<img src="'.get_bloginfo("template_url").'/images/thumb-default.gif" />
This outputs an http img src – how can I convert that to https?
WordPress checks the return value of
is_ssl()
before creating URLs usingget_bloginfo()
. If the function returns true, it creates https URLs. If it returns false, it creates http URLs.From the WordPress source …
So … if the request was made over https or if the request came in over port 443, then
get_bloginfo()
will return anhttps://
URL. In reality, if you’re forcing https anyway, you should force all requests to port 80 (http) over to port 443 (https) … but that’s a server configuration issue, not a WordPress issue.Alternatively, you could hook into a filter and replace http with https …
Just use:
Had you checked this when requesting page via
http
orhttps
link? What doesis_ssl()
return for you?I don’t have SSL-capable stack to test at moment, but I am pretty sure that WP functions that put together links should be aware of SSL and output correct version.
Using the home_url() function will automatically detect ssl and change protocols.
To add to the fix proposed by EAMann I have made some changes for version 3.5:
I’d like to note that this redirect thing may be very helpful, but my server redirects SSL to another port and is not detected by WP so for me it’s an annoyance.