Thread Starter
dimizu
(@dimizu)
Ok, I answer myself 😉
The problem is the filter:
add_filter( 'wp_calculate_image_srcset_meta', '__return_null' );
in the icp-functions.php. This filter strips all image attributes for all images in the page, also srcset etc of images that not are in the carousel.
My solution:
a) I have deleted the line with the filter
b) then before this line:
$output .= "<div class='carousel-item'>{$image_output}</div>";
I striped the code in $image_output with:
$image_output=stripImageAttributes($image_output,'srcset');
$image_output=stripImageAttributes($image_output,'sizes');
Function stripImageAttributes:
function stripImageAttributes($html,$stripAttribut)
{
// init document
$doc = new DOMDocument();
$doc->loadHTML('<!doctype html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body>' . $html . '</body></html>');
// init xpath
$xpath = new DOMXPath($doc);
// process images
$body = $xpath->query('/html/body')->item(0);
foreach ($xpath->query('//img', $body) as $image) {
$toRemove = null;
foreach ($image->attributes as $attr) {
if ($stripAttribut == $attr->name) {
$toRemove[] = $attr;
}
}
if ($toRemove) {
foreach ($toRemove as $attr) {
$image->removeAttribute($attr->name);
}
}
}
// convert the document back to a HTML string
$html = '';
foreach ($body->childNodes as $node) {
$html .= $doc->saveHTML($node);
}
return $html;
}
(Function from: http://stackoverflow.com/questions/38023033/remove-everything-else-from-an-image-link-but-keep-src/38023322)
Now works for me.
Maybe you can integrate a similar or better solution into the next version.
greetings
Hi @dimizu
Thank you very much for your solution, really appreciate it 🙂
I’m going to have to dig around in the code a bit and apply it in the next release…
pls, fix this bug, i creating the project on wp 4.7.2 and “the_post_thumbnail” is broken after enable yoast seo plugin. path to the main thumbnail image replace to this sh*t http://localhost/xxxxxx/www/wp-content/uploads/image_carousel_thumbs/xxxxxx-550×200-n1cwcejhdhowie1ywtxrw432srvk5ckrml8l6pf8zo.jpg thx