Skip to content

Commit

Permalink
Fixes srcset not loading due to SSL/HTTPS issues
Browse files Browse the repository at this point in the history
When SSL/HTTPS is not properly configured on a website the srcset
attribute might try to load images via HTTP causing the browser to
block the loading of "mixed content".
  • Loading branch information
cabrerahector committed Jun 4, 2021
1 parent 5a7e867 commit d2737ea
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -841,8 +841,14 @@ public function render($src, $size, $class, $alt = '', $error = null)
$img_tag = '<!-- ' . $error . ' --> ';
}

// Make sure we use the right protocol
$src = esc_url(is_ssl() ? str_ireplace("http://", "https://", $src) : $src);
// Get srcset, if available
$srcset = $this->get_srcset($src);
$src = 'src="' . esc_url(is_ssl() ? str_ireplace("http://", "https://", $src) : $src) . '"' . $srcset;

$src = 'src="' . $src. '"' . $srcset;

// Lazy Load attribute, if enabled
$lazyload = ( $this->admin_options['tools']['markup']['thumbnail']['lazyload'] ) ? ' loading="lazy"' : '';

$img_tag .= '<img ' . $src . ' width="' . $size[0] . '" height="' . $size[1] . '" alt="' . esc_attr($alt) . '" class="' . esc_attr($class) . '"' . $lazyload . ' />';
Expand Down

0 comments on commit d2737ea

Please sign in to comment.