Soliloquy Documentation

Documentation, Reference Materials, and Tutorials for Soliloquy

Dynamic: Display Fallback Slider if No Images Found

Important: This doc assumes you’re comfortable creating and/or editing PHP files in your WordPress installation and is intended for advanced users.

Note: This document is relevant only if you have a Developer or Master license and you’re using the Dynamic Addon or the Featured Content Addon.

Using the Featured Content Addon? You can also specify a fallback image within the Slider tab’s configuration options when editing your Featured Content slider in the event the post(s) or page(s) populating your slider don’t have a featured image set.

When working with Dynamic sliders, sometimes it may be helpful to have a safety net fallback in the event a slider doesn’t have any images to display.

You can set a default fallback slider by adding the following code to your active theme’s functions.php file, and changing the YOUR_SLIDER_ID_HERE text to match the ID of the slider you want to use as a fallback:

add_filter( 'soliloquy_pre_data', 'tgm_soliloquy_check_slider_images', 10, 2 );
function tgm_soliloquy_check_slider_images( $data, $slider_id ) {
	// If there are no images, output a different slider.
	if ( empty( $data['slider'] ) ) {
                return Soliloquy::get_instance()->get_slider( 'YOUR_SLIDER_ID_HERE' );
	// Return the empty slider which will stop the slider from initializing.	
	return $data;