Envira Gallery Documentation

Documentation, Reference Materials and Tutorials for Envira Gallery

How to Limit the Caption Length in the Lightbox for Base Lightbox Themes

Would you like to control the limit of the caption length in your Base lightbox themes? Envira will help you easily create something custom on your site that can help you do exactly that. This guide will show you how to control the text limit on captions for your Base (Dark) or Base (Light) lightbox theme.

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 limit the caption length, we’ll need to create and upload a basic WordPress plugin.

To control the amount of text that shows in the top of your lightbox view, just add the following code to a new file at wp-content/plugins/envira-limit-caption-text.php.

* Plugin Name: Envira Gallery - Limit Caption Text
* Plugin URI: https://enviragallery.com
* Version: 1.0.0
* Author: Envira Gallery Team
* Author URI: https://enviragallery.com
* Description: Limits caption text for Base LB Themes
* Enable comments on Envira Galleries
* @since 1.0.0
add_filter('envira_gallery_output_lightbox_caption_limit', 'example_envira_gallery_output_lightbox_caption_limit', 10, 5 ); 

function example_envira_gallery_output_lightbox_caption_limit( $limit, $data, $id, $item, $i ) { 
     return 50; 
In the above code you can see return 50;. This means only that the plugin will limit the caption length to 50 characters. You can easily change that number to whatever you wish before saving the file.

Not sure how to do that? Just follow these steps:

  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 above into the file and save the file as envira-limit-caption-text.php
  3. Once you have 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.

Your next step is to activate the plugin you just uploaded. Simply navigate to the Plugins from within your WordPress dashboard and activate the Envira Gallery – Limit Caption Text plugin.

Activate the custom plugin to begin controlling the caption length

Here’s what the caption area in the lightbox looked like before the text was limited with the plugin:

before the limit was applied to the caption text

And now we can see what the caption looks like after installing the plugin and limiting the length to 50 characters:

after the limit was applied to the caption text

And that’s it! You are now controlling the lightbox caption text limits.

If you’d like to extend Envira further, check out some of our other tutorials such as How to Remove WordPress Image Compression.

A: Please check the Lightbox tab to see which Lightbox Theme you are using. This plugin will only limit the caption text for the Lightbox Theme Base (Dark) and Base (Light).

confirm you've selected either the Base (Dark) or Base (Light) lightbox theme

A: Navigate to Plugins » Editor and select the Envira Gallery – Limit caption count on Base Lightbox Themes from the drowpdown and click Select. This will allow you to easily change the return 50; to what ever you wish. Once you have edited the number, remember to click the Update File button at the bottom of the screen to save the changes.