• Very great plugin thanks.

    There is an incompatibility with WordPress standard functions.

    If your plugin is active, then overwrites the standard the_post_thumbnail function of wordpress.

    When I use this in my template:
    the_post_thumbnail('my_thumbnail_teaser');
    the result with your plugin not active is:
    <img src="https://localhost/xxxxxx/wp-content/uploads/2016/12/xxxxx-550x200.jpg" class="attachment-my_thumbnail_teaser size-my_thumbnail_teaser wp-post-image" alt="" width="550" height="200">

    But when your pugin is active then the result is:
    <img src="https://localhost/xxxxxx/www/wp-content/uploads/image_carousel_thumbs/xxxxxx-550x200-n1cwcejhdhowie1ywtxrw432srvk5ckrml8l6pf8zo.jpg" class="attachment-my_thumbnail_teaser size-my_thumbnail_teaser wp-post-image" alt="" width="550" height="200">

    Do you have a solution?

    • This topic was modified 7 years, 11 months ago by dimizu.
Viewing 3 replies - 1 through 3 (of 3 total)
  • 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: https://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

    Plugin Author GhozyLab

    (@ghozylab)

    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 https://localhost/xxxxxx/www/wp-content/uploads/image_carousel_thumbs/xxxxxx-550×200-n1cwcejhdhowie1ywtxrw432srvk5ckrml8l6pf8zo.jpg thx

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Incompatible with wp functions – Plugin overwrite the_post_thumbnail function’ is closed to new replies.