I have been using the following code to display the images in Bootstrap carousel:
<a href="<?php echo get_page_link( $page->ID ); ?>">
<?php $image = wp_get_attachment_image( get_post_thumbnail_id($page->ID), 'child-page','', array('class' => "img-responsive img-shadow", 'alt' => get_the_title())) ?>
<?php echo $image; ?>
</a>
I have added add_image_size( 'child-page', 400, 200, true );
in functions.php but it is displaying the images of variable height.
How do I control size without having to optimize the images?
Why not put in your style.css
.carousel-inner img{
width: 400px;
height: 200px;
}
Of course you can force your images to fit a specific width and height as proposed by @rockStar using CSS, however, that will result in ugly disproportionate images. There are plugins which allow you - effortlessly - to regenerate WordPress thumbnails in the dimensions you need them to be:
Cheers.
i added the following css
.gallery-slider .thumbnail>img, .thumbnail a>img, .carousel-inner>.item>img, .carousel-inner>.item>a>img {
display: block;
max-width: 100%;
height: 170px !important;
}
to solve the problem