I already have the two separate codes, both working, but I do not know how to use them in the same thumbnail.
This code set a default fallback image if no image can be found in a post.
<a href="<?php the_permalink(); ?>">
<?php if ( has_post_thumbnail() )
the_post_thumbnail( array(600,600) );
else
echo '<img src="' . trailingslashit( get_stylesheet_directory_uri() ) . 'images/default-thumbnail.svg' . '" />';
?>
</a>
And this code turn the thumbnail responsive.
<? if( has_post_thumbnail( $post_id ) ): ?>
<img title="" alt="" src="<?=wp_get_attachment_url( get_post_thumbnail_id() ); ?>" style="width:100%; height:auto;">
<? endif; ?>
I don't know PHP. I would like to remove this line below from the first code to resize the image to width 100 %. I don't want the fixed size of 600 x 600px.
the_post_thumbnail( array(600,600) );
Somebody can help me?
[ SOLUTION!! ] Thank you, Society43.
<a href="<?php the_permalink(); ?>">
<?php if( has_post_thumbnail( $post_id ) ) { ?>
<img src="<?=wp_get_attachment_url( get_post_thumbnail_id() ); ?>" style="width:100%; height:auto;">
<?php } else {
echo '<img src="' . trailingslashit( get_stylesheet_directory_uri() ) . 'images/default-thumbnail.svg' . '" />';
} ?>
</a>