Add a check to see if the $imgHtml has been initialized before attempt to use it, this prevents php error on preview mode with no images.