Support » Fixing WordPress » Thumbnails generated with wrong css size class and img atributes

  • Hi, I have an custom thumbnail size created. But wp is generating to me still 100px thumbnail sizes into classes and into img tag atributes.

    in my child theme funtion.php I puted:

    add_theme_support( 'post-thumbnails' );
    add_image_size( 'dk-thumb', 180, 180, true );

    In WP backend setting also I changed thumbnail size accordingly.

    I regenerated thumbnails, but still, wp generates me a wrong size classes and img size atrributes. …?!? (attachment-100×100 size-100×100 and width=”100″ height=”100″, also the responsive sizes are wrongly generated sizes=”(max-width: 100px) 100vw, 100px)

    <img width="100" height="100" src="http://www.danielkral.cz/wp-content/uploads/K9mailLogo-180x180.png" class="attachment-100x100 size-100x100 wp-post-image" alt="K9mailLogo" title="K-9 email" srcset="http://www.danielkral.cz/wp-content/uploads/K9mailLogo-180x180.png 180w, http://www.danielkral.cz/wp-content/uploads/K9mailLogo.png 300w" sizes="(max-width: 100px) 100vw, 100px">

    Thank you for advice!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Did you add it to your template file (i.e. – single.php)?

    (from: https://developer.wordpress.org/reference/functions/add_image_size/)

    Using the New Image Sizes

    Now that you’ve defined some custom image sizes, there are a variety of ways that you can use them.
    For Featured Images

    To use your custom image sizes for a post’s featured image, you can use the_post_thumbnail() in the appropriate theme template file…

    Note: To enable featured images the current theme must include add_theme_support( ‘post-thumbnails’ ); in its functions.php file. See also Post Thumbnails.

    if ( has_post_thumbnail() ) {
        the_post_thumbnail( 'your-custom-size' );
    }

    Or Admin Media Library:

    For Media Library Images (Admin)

    You can also make your custom sizes selectable from your WordPress admin. To do so, you have to use the image_size_names_choose hook to assign them a normal, human-readable name…

    add_filter( 'image_size_names_choose', 'my_custom_sizes' );
    
    function my_custom_sizes( $sizes ) {
        return array_merge( $sizes, array(
            'your-custom-size' => __( 'Your Custom Size Name' ),
        ) );
    }

    Thanks, I have this issue only when using excerpt on my main page, in single page even it is original thumbnail its resized corectly because ut was setted in media setting on backend… so this, Its happening on main page when using excepts.

    Also i observed that issue is gone, when switch to other template, so I will have to check my function file…
    Thank you, but I do not uderstand to it much, even if I did put your code the image appears in position I putted the code, so its totally wrong… you code should only change the value of variable not the print image…
    I did read it before I wrote here… Im solving it and googling all day…

    Update: I totally deleted my function.php and problem persist, so really its somewhere in other template files…

    Update2
    : this is my single article img, its correct, but on main page where are excerpts there is wrong sizes as I posted here before.

    <img src="http://www.danielkral.cz/wp-content/uploads/K9mailLogo-180x180.png" alt="K9mailLogo" width="180" height="180" class="alignleft size100px size-thumbnail wp-image-5330" srcset="http://www.danielkral.cz/wp-content/uploads/K9mailLogo-180x180.png 180w, http://www.danielkral.cz/wp-content/uploads/K9mailLogo.png 300w" sizes="(max-width: 180px) 100vw, 180px">

    Please understand that I dont need specially sized images, it is enough to change default thumbnail size, what I even did in wp settings… but now Im facing this issue, that thumnails css and sizes are incorect when displayed on archive template, sorry for longer descrition I should do that first time yet… 😉

    Update 3: I will keep it simple, deleted all files .php and .js from theme folder, issue persist. Other wp default templates works normally.
    Issue: wrong sizes attachment-100×100 size-100×100 and width=”100″ height=”100″, also the responsive sizes are wrongly generated sizes=”(max-width: 100px) 100vw, 100px at home page and archives. But on single page it is correct.
    Have done: changed default thumnail size at settings media backend, regenerated thumbnails. Leaving a try to put custom size. Default size changed thumbnail must work.

    I found today somethimg could be linked to my issue (maybe not becose there is AJAX used): http://wordpress.stackexchange.com/questions/42860/wp-get-attachment-image-returns-different-image-size

    Now Im searaching for the function which is responsible for wordpress that gets the image dimensions to check it, actually have not found so if you know please share… thx Im probably close cos im rewieving wp_calculate_image_sizes function and theirs variables…

    Actually i can get rid of the dimension atributes on image even I can filter classes but I do not want to do it, I want to know why Im getting 100×100 image size on image with other size…

    actually thinking about _wp_get_image_size_from_meta which i think takes image size from image meta someway… Im stuck dont know where to track it…

    even I made several sizes like in screenshot that works as you can see on printscreen, even default thumbnail have 180px… but still in <img tag on main page http://www.danielkral.cz/clanky have 100px dimensions:

    <img width="100" height="100"
    src="http://www.danielkral.cz/wp-content/uploads/K9mailLogo-180x180.png"
    class="attachment-100x100 size-100x100 wp-post-image"
    alt="K9mailLogo" title="K-9 email"
    srcset="http://www.danielkral.cz/wp-content/uploads/K9mailLogo-180x180.png 180w,
     http://www.danielkral.cz/wp-content/uploads/K9mailLogo.png 300w"
    sizes="(max-width: 100px) 100vw, 100px">

    Sorry all Im totally dissapoitnted, when I unsett all custom sizes and regenerated thumbnails I put in function.php

    function wpdocs_setup_theme() {
      add_theme_support( 'post-thumbnails' );
      set_post_thumbnail_size( 180, 180, true );
    }
    add_action( 'after_setup_theme', 'wpdocs_setup_theme' );

    And regenerate thumbnails again, and whats happen?! When I want to insert image into post it offers me only square images from 180 over 300 to 800px … but squares… anyone know what Im doing wrong? I set only thumbnail to square! ?! – Im stupid It was square image… lol… rofl…

    Very Interesting partial result!!!
    I had to comment out part of code becose it is not cropping thumbnails at all! Explanation in comment:

    add_theme_support( 'post-thumbnails' );
    //set_post_thumbnail_size( 180, 180, true );  // not works with cropping setted in media backend!!!
    add_image_size( 'related', 150, 100, true ); //related , must regenerate thumnails after

    Unfortunatelly Im still facing wrong dimension issue…

    Moving this topic to theme forum, because after long investigation, Im suppossing its parent theme issue, I have tested also WP default themes, but it has not excerpts with images. So I will post this to thematictheme.com

    My end results are that issue will arise, only if excerpt printed out on screen…

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Thumbnails generated with wrong css size class and img atributes’ is closed to new replies.