I need to decrease the height of the image attached in the wordpress page. i had tried several methods but i am unable to solve it.It is not getting any change when i am adding image size Topbannerimg in img src.
my wp_query to dispaly image
<?php
$homepage = get_page_by_title('Top Banner');
$attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_parent' => $homepage->ID,
) );
if ( $attachments ) {
echo '<section class="topBanner">';
foreach ( $attachments as $attachment ) { ?>
<a href="<?php if($attachment->post_excerpt){echo $attachment->post_excerpt;}else{echo "#";}?>">
<img src="<?php echo wp_get_attachment_url($attachment->ID); ?>">
</a>
<?php }
echo '</section>';
}
wp_reset_postdata();?>
size mentioned in functions.php
add_image_size( 'TopBannerImg', 1800, 500, true );
You can use wp_get_attachment_image function to display image. Please refer: https://developer.wordpress.org/reference/functions/wp_get_attachment_image/ . Pass image thumbnail name as second paremeter.
Checkout this code:
First parameter for width and second for height.
<?php the_post_thumbnail( array( 480, 277 ) ); ?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.