This article covers the simple steps on how to define a default image that will be displayed to the visitors in case the actual (embedded) image no longer exists.
This article applies to our cloud hosting packages only.
It only requires three lines of code that need to be added to the server configuration (NGINX in our case).
- Login to the cloud panel.
- Click
Applications
in the main menu and click on the desired domain. - Click
Site Settings
in the application menu and scroll to the bottom of the page. - Click the
Custom Server Directives
tab.
Add the following code at the end of the existing code (if it exists):
location ~* \.(?:jpg|jpeg|gif|png)$ {
include dihost_params_static;
expires 60d;
try_files $uri /wp-content/uploads/default_image_fallback.jpg;
}
The fallback image must be uploaded at the path displayed in the code above. The path can be changed accordingly and does not need to be in the wp-content folder.
Save the changes and after one minute all JPG, JPEG, GIF and PNG images, that no longer exist, will display the defined the fallback image.