Replace a no-featured image post blank image holding

For posts that do not have a featured image, I would like to replace the default holding image with custom one.

  • Adam Czajczyk
    • Support Gorilla

    Hello Bevan

    I hope you’re well today and thank you for your question!

    Replacing the image with CSS could be done with some “trick” (and would be more of “covering it with another image” rather than replacing) but I think it would be better to use a built-in filter hook to change that:

    <?php
    function myprefix_remove_vc_grid_fallback_img( $output ) {
    if ( ! get_post_thumbnail_id() ) {
    return 'IMAGE_URL_HERE';
    }
    return $output;
    }
    add_filter( 'vc_gitem_template_attribute_post_image_url', 'myprefix_remove_vc_grid_fallback_img', 99 );

    To apply it to the site:

    1. create an empty file with a .php extension (e.g. “my-post-placeholder-image.php”:wink:

    2. copy and paste this entire code into that file

    3. replace

    IMAGE_URL_HERE

    with an actual URL of your new image

    4. save the file and upload it to the

    /wp-content/mu-plugins

    folder on your server, using FTP or cPanel’s “File Manager”. If there’s no “mu-plugins” folder directly in “/wp-content” folder, just create an empty one first.

    Give it a try please and let me know if it worked for you.

    Best regards,

    Adam

  • Bevan
    • Site Builder, Child of Zeus

    Thanks Adam but this didn’t seem to bring in the image. The image changed from square to similar dimensions as the umbrella image but it still has the blue placeholder there. I added

    <?php
    function myprefix_remove_vc_grid_fallback_img( $output ) {
    if ( ! get_post_thumbnail_id() ) {
    return 'Ihttps://nationalfloodforum.org.uk/wp-content/uploads/2017/05/Blog-Feature-Image-1.jpg';
    }
    return $output;
    }
    add_filter( 'vc_gitem_template_attribute_post_image_url', 'myprefix_remove_vc_grid_fallback_img', 99 );

  • Adam Czajczyk
    • Support Gorilla

    Hi Bevan

    Thank you for response!

    I checked the site and the code seems to be working as expected but apparently there is some inline CSS that gets in a way, settings this blue(ish) image – that wouldn’t be much of an issue but at the same time for some reason the real image is set to be hidden with CSS.

    Therefore, I’ve added this CSS to the “Theme Options -> Custom CSS” (at the very bottom):

    /* post placeholder image additional fix */
    .vc_gitem-zone-img {
    visibility:visible!important;
    }

    The mu-plugin (so previously added php code) together with this CSS and after clearing cache on site seems to be working fine now :slight_smile:

    Best regards,

    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.