G
G
Georgy Khasanov2020-06-28 12:47:34
WordPress
Georgy Khasanov, 2020-06-28 12:47:34

How can I resize the_post_thumbnail() images to 100% width and 512px height so the image quality doesn't get squished?

If I use this code, then the image is flattened. How to do so that it does not flatten?

<?php get_header() ?>
<?php 
the_post(); ?>
<?php $image_id = get_post_thumbnail_id(); ?>
<?php $image_attributes = wp_get_attachment_image_src( $image_id, 'full');  ?>
<img src="<?php echo $image_attributes[0]; ?>" width="100%" height="512px">
<?php
the_title('<h1 class="post-title">', '</h1>');
echo '<div class="post-content">';
the_content();
echo '</div>';
?>
<?php get_footer() ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Ankhena, 2020-06-28
@c0mbat-un1t

Use object-fit: cover
https://webref.ru/css/object-fit

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question