简体   繁体   中英

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

在此处输入图像描述

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

在此处输入图像描述

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 } ?>

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM