'add a no image placeholder on elementor pro post element if there is no featured image

is there filter of some sort that can add a image if there is no featured image present when using the Elementor pro "post" element.

Because the title goes up if there is no image placed and it breaks the sites display

enter image description here

want to add a placeholder image like below when no featured image is available

enter image description here



Solution 1:[1]

You can add this filter to you theme functions.php :

function mlnc_filter_post_thumbnail_html( $image_placeholder ) {
    // If there is no post thumbnail,
    // Return a default image
    if ( '' == $image_placeholder ) {
        return '<img src="' . get_template_directory_uri() . '/images/default-thumbnail.png"/>';
    }
    // Else, return the post thumbnail
    return $image_placeholder;
}
add_filter( 'post_thumbnail_html', 'mlnc_filter_post_thumbnail_html' );

Another way is to go where the image is outputting and add an If statement like below:

<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
} else { ?>
<img src="<?php bloginfo('template_directory'); ?>/images/default-image.jpg"/>
<?php } ?>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kaize