• Hi, I am working on a site, that needs to have the images width=”” height=”” added in a certain class. The site does not have this on images,

    So it is like this now,

    <div class=”myclass”>
    <img src=”path” alt=”title”>
    </div>

    But I need it like this,

    <img width=”” height=”” src=”” alt=””>

    It is a a high end theme, responsive with a child theme.

    So I would like to see, a code in the function.php that will assign this to the images in certain class, or classes. I am hoping to have about 4 different sections with different classes. So may be feature will be 300×400 pixels, the second feature images will be 250×250.

    And so on, can that be done?

    Thanks,

Viewing 1 replies (of 1 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    You can create your own thumbnails when you upload images (will require a reupload of images or plugin that does this): http://codex.wordpress.org/Function_Reference/add_image_size

    For featured images you can call “the_post_thumbnail” along with the custom image size you created, e.g.:

    if ( has_post_thumbnail() ) {
    	the_post_thumbnail( 'childtheme-large' );
    }

    See if you have the image attributes then

Viewing 1 replies (of 1 total)
  • The topic ‘Adding img width="" height="" via Function.php’ is closed to new replies.