4

I am using FORCE_SSL_ADMIN in wp-config.php so everytime I upload a new image and inserted into the post, it is using SSL version

e.g.

<img src="https://www.example.com/wp-content/uploads/2013/01/test.png" ..

My blog is using HTTP in the public side, so how to make the upload path as rotocol independent, e.g.

<img src="//www.example.com/wp-content/uploads/2013/01/test.png" ..
1

1 Answer 1

0

You can define a function to remove the protocol and hook it to the attachment URL:

function wpse_79958_remove_protocol_from_attachment($url) {
    $url = str_replace(array('http:', 'https:'), '', $url);
    return $url;
}
add_filter( 'attachment_link', 'wpse_79958_remove_protocol_from_attachment' );

Also consider to use relative URLs for attachments by using WordPress builtin function wp_make_link_relative:

add_filter( 'attachment_link', 'wp_make_link_relative' );

Place this code to your functions.php. Not tested though.

Update: already tested

6
  • Thanks first, but the attachment_link link work only when there is a link point to the attachment, but I am referring to the direct image file.
    – Yoga
    Commented Jan 17, 2013 at 10:18
  • If you are pointing to the file manually, so keep in mind preferred protocol yourselves.
    – Max Yudin
    Commented Jan 18, 2013 at 17:04
  • Nope, I am saying you plugin will not work when I follow the steps: Add Media -> Select the image -> [In the Attachment Display Setting] -> Link To Media File. You plugin will only work if I select the "Link To Attachment Page"
    – Yoga
    Commented Jan 26, 2013 at 10:01
  • I can not reproduce your situation. I've forced admin SSL on localhost, but I still have new uploads with http rather than https. Anyway, it's easy to remove the protocol from the URL manually. Also there is no straight hook for this.
    – Max Yudin
    Commented Jan 31, 2013 at 10:57
  • This is not an answer actually. This should receive some attention as would be really useful. Commented Sep 18, 2014 at 21:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.