Soliloquy Documentation

Documentation, Reference Materials, and Tutorials for Soliloquy

Set a Default Caption

Would you like your slider to have a default caption when no caption exists? Soliloquy can easily help you set the image title to the caption when a caption hasn’t been entered. We’ll walk you through how to set a default caption.

Note: This tutorial is a bit more technical than our other docs, but we’ll walk you through the process step by step. In order to set a default caption, we’ll need to create and upload a basic WordPress plugin.


Creating the Plugin

To set the image title as a fallback for your captions, just add the following code to a new file at wp-content/plugins/soliloquy-defualt-caption-image-title.php.

[php]<?php

/**
* Plugin Name: Soliloquy – Default Caption
* Plugin URI: https://soliloquywp.com
* Description: Plugin that set the image title as the caption when no caption exists
* Author: Soliloquy Team
* Author URI: https://soliloquywp.com
* Version: 1.0
* Domain Path: languages
*/

add_filter( ‘soliloquy_output_item_data’, ‘tgm_filter_caption_to_image_title’, 10, 3 );
function tgm_filter_caption_to_image_title( $image, $id, $data) {

// Fallback to image title if no caption is set.
if ( ‘image’ == $image[‘type’] ) {
$image[‘caption’] = ! empty( $image[‘caption’] ) ? $image[‘caption’] : $image[‘title’];
}

// Return the modified data.
return $image;

}[/php]

If you’re unsure how to create a plugin file, follow these steps below:

  1. Open a text file and make sure that it is a plain text document. You can use a plain text editor like Notepad or a code editor of your choice.
  2. Next, copy and paste the code shown above into the file and save the file as soliloquy-defualt-caption-image-title.php
  3. Once you’ve saved the file you can easily upload this directly to your /plugins directory on your server using FTP or you can right-click on the text document and zip (or compress).
  4. Finally, log in to your WordPress dashboard and go to Plugins » Add New » Upload Plugin and upload the .zip file you just created in the previous step.

Activate the Plugin

Your next step is to activate the plugin you just uploaded. Simply navigate to the Plugins from within your WordPress dashboard and activate the Soliloquy – Default Caption plugin.

Activate the custom plugin to set a default caption on your slider images

That’s it! You’ve set the image title as a default caption for all slider iamges. Would you like to extend Soliloquy further? Take a look at our tutorial on How to White Label Soliloquy.