You should check if those files exist before you output that div. You can clean up your markup and get rid of that onerror
call by wrapping each image div in a file_exists
check. Use a ternary to check if the file exists and set the $image
variable if it is. Like so:
$image1 = "/nomes-unisex/" . $post->post_name . ".jpg";
$image2 = "/nomes-femininos/" . $post->post_name . ".jpg";
$image3 = "/nomes-masculinos/" . $post->post_name . ".jpg";
$uploadDir = wp_get_upload_dir();
$image1 = file_exists($uploadDir['basedir'] . $image1) ? $uploadDir['baseurl'] . $image1 : '';
$image2 = file_exists($uploadDir['basedir'] . $image2) ? $uploadDir['baseurl'] . $image2 : '';
$image3 = file_exists($uploadDir['basedir'] . $image3) ? $uploadDir['baseurl'] . $image3 : '';
?>
<div class="acf_imgs-centro1">
<?php if ($image1 || $image2 || $image3) {
?>
<h2 class="imgs_h2">Compartilhe nas redes sociais</h2>
<?php if ($image1) { ?>
<div class="img-neutra">
<img alt="Significado de <?php the_title(); ?>" src="https://wordpress.stackexchange.com/questions/330251/<?php echo $image1; ?>">
</div>
<?php }
if ($image2) { ?>
<div class="img-fem">
<img alt="Significado de <?php the_title(); ?>" src="<?php echo $image2; ?>">
</div>
<?php }
if ($image3) { ?>
<div class="img-masc">
<img alt="Significado de <?php the_title(); ?>" src="<?php echo $image3; ?>">
</div>
<?php }
} ?>
</div>