---
title: "How to conditionally display an image or a placeholder"
date: 2026-04-23
author: "GravityKit"
link: "https://www.gravitykit.com/docs/gravityview/shortcodes/how-to-conditionally-display-an-image-or-a-placeholder/"
---

If you wish to display an image only if specific criteria match another field's value or even display a placeholder image in case the original image is not present, you can do that with either the  shortcode or with the Field Conditional Logic functionality from the [Advanced Filter extension](https://www.gravitykit.com/products/advanced-filter/).

## Using the  shortcode

In this View, the cat named "Charlie" doesn't have a photo:

![Placeholder used for missing photo of cat Charlie in table](https://www.gravitykit.com/wp-content/uploads/2025/10/file-vf4oa8zEra.png)
*So, we will be replacing the Cat Photo field, which is a File Upload field, with a*[Custom Content field](https://www.gravitykit.com/docs/gravityview/getting-started-gravityview/using-the-custom-content-field/) to write our  shortcode inside:

![Conditional code to display a cat photo or a placeholder image based on availability](https://www.gravitykit.com/wp-content/uploads/2025/10/file-3jv4JnG3cx.png)
*This is the  code we used on the image above:*
```
[gvlogic if="{Cat Photo:2}"]

[else]

[/gvlogic]
```

```
[gvlogic if="{Cat Photo:2}"]

[else]

[/gvlogic]
```

When outputting a field value inside an HTML tag, always use the Modifier [:esc\_html](https://www.gravitykit.com/docs/gravityview/merge-tags/merge-tag-modifiers/) to prevent it from breaking your website's HTML.

And here's our View now with a placeholder image for an empty File Upload field:

![Table with cat names. Placeholder icon used when photos are unavailable](https://www.gravitykit.com/wp-content/uploads/2025/10/file-mouFWwp6bL.png)

## Using Field Conditional Logic

To use this feature, you must have installed the Advanced Filter plugin available only to the Core + Extensions or All Access licenses.

This functionality is more straightforward than using the  shortcode because it doesn't require any custom code; it's as simple as specifying the conditions for the Cat Photo field in the View editor:

![Options for displaying an image based on conditional logic settings](https://www.gravitykit.com/wp-content/uploads/2025/10/file-E6zOMiGK6R.png)