How to Hide the Brizy Placeholder Image on Your Blog Posts When No Featured Image Is Set

If you're using Brizy for your blog, you might have noticed that a placeholder image box appears in posts that don’t have a Featured Image. While some posts may have images, others might not, and leaving a large empty space or placeholder can disrupt the flow of your blog feed.

Unfortunately, Brizy doesn’t offer a built-in option to hide the placeholder image box if no Featured Image is uploaded.

To address the issue, I’ve tested the following PHP code snippet in my environment, which should work if you already have a dynamic template for your posts and have added a CSS class for the featured image. In this case, the class .hide_featured will be targeted by the function below to hide the placeholder. 

.hide_featured class
function hide_featured_if_no_thumbnail($classes) {
    if (!has_post_thumbnail()) {
        // Add a custom class to hide the .hide_featured element
        $classes[] = 'hide-featured';
    }
    return $classes;
}
add_filter('body_class', 'hide_featured_if_no_thumbnail');

function add_custom_css_to_hide_featured() {
    if (is_single() && !has_post_thumbnail()) {
        echo '<style>
            .hide_featured {
                display: none !important;
            }
        </style>';
    }
}
add_action('wp_head', 'add_custom_css_to_hide_featured');

To add this function, you'll need the WPCode plugin. Alternatively, if you're using a child theme, you can add the code to the functions.php file.

  1. Create a new code snippet and copy/paste the code above, selecting "PHP Snippet" since this is a PHP script.
  2. Name the custom function.
  3. Click "Update."
  4. Set the snippet to "Active."
WP Code screenshot

When copying and pasting the code, make sure to follow the exact format shown in the screenshot. Afterward, visit a post without a featured image and preview it in your browser.

This is demonstrated on this screencast:

While Brizy doesn’t offer a built-in setting to hide the placeholder image when no Featured Image is present, this PHP code snippet provides a quick fix. By adding this code to your site, you can ensure that only posts with a Featured Image display one, leaving the posts without an image looking neat without an empty placeholder box.

If you're comfortable adding custom PHP code to your WordPress site, this solution should work seamlessly. And if you're not familiar with editing your theme files, it’s a good idea to back up your site or consult a developer for assistance.

Leave a Comment

Back to Top