• Resolved customle

    (@customle)


    How can I limit the number of characters in captions in galleries? When the length is too long it messes up the columns. Instead of showing 4 thumbnails per row, only 1 will show if a caption is too long on one of the thumbnails.

    I would like it to display the first 20 characters followed by “…”, such as “Four Towers Custom Busi …”

    The page I need help with: [log in to see the link]

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thanks for your question and for the link to your site; very helpful.

    You can limit the length of your caption by using one of the “Field-level option/format values” (the Settings/Media Library Assistant Documentation tab has a complete list).

    Try adding this parameter to your [mla_gallery] shortcode:

    mla_caption="{+post_excerpt,substr(0,20)+}..."

    That will limit the caption to 23 characters including the three periods. The only drawback to this solution is that short captions will also contain the periods. That shouldn’t be a big problem in your application, however.

    I am marking this topic resolved, but please update it if you have any problems or further questions regarding the above suggestion. Thanks for your interest in the plugin.

    Thread Starter customle

    (@customle)

    It works great, thank you; however, is there a way to allow all of the caption content to show when the full image is opened? I wanted the caption showing the shortened version in the thumbnail galleries only.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update confirming that the fix is working for you.

    Regarding your “ full image is opened” question, it looks like you are using a “lightbox” plugin or theme feature to display and navigate among larger images when a thumbnail is clicked. The lightbox picks up the caption value from the value displayed below the thumbnail, which is truncated.

    I don’t know if the lightbox you are using has any ability to use a different source for its larger images. If you can tell me exactly what plugin or theme supplies the lightbox functionality I can investigate further. You could also contact the lightbox developer and see if they can help you.

    Thread Starter customle

    (@customle)

    Thank you for your quick response. I am currently using WP Featherlight as my lightbox plugin.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for the details on your lightbox. I installed it and will investigate how it can be used to alter the captions displayed in the full-size slideshow. The plugin details says:

    Developer Notes
    While there are no options in the plugin, there are some handy filters to modify the default behavior. As of 0.3.0 all images which use the default WordPress captions will also include a caption when the image is lightboxed. To disable this behavior, filter wp_featherlight_captions to false.

    That’s not what you want, but it may be possible to add a bit of JavaScript to get a better result. I am out of town until next Tuesday but will work on this after I return home. Thanks for your patience.

    Thread Starter customle

    (@customle)

    I’m not committed to WP Featherlight so I do not mind switching lightboxes if you know of one that does allow this feature.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update and especially for your patience in awaiting my response. I haven’t forgotten you but I’ve been busy with a number of other projects.

    I believe WP Featherlight is a good choice and can be made to work for your application. It has a number of JavaScript hooks, including one (afterContent) that is called just after the lightbox content is prepared. I have been working on some code that uses this filter to substitute the complete caption for the abbreviated version shown in the thumbnail display. So far I have been unable to get this working by adding some JavaScript to the WordPress page content, and I now plan to create a small custom plugin to package the code and send it to the browser.

    I am traveling until April 9 and I will have to complete the work when I return home. Thanks again for your patience and your understanding!

    Thread Starter customle

    (@customle)

    Thanks a million.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for patience in awaiting this update! I have uploaded a new MLA Development Version dated 20180409 that contains a solution for the “full image caption” requirement.

    To get the Development Version, click this link to download the Development Version ZIP archive:

    https://downloads.wordpress.org/plugin/media-library-assistant.zip

    Once you have the ZIP archive on your system:

    1. Login to your site’s Admin area and navigate to Plugins/Installed Plugins.
    2. Find Media Library Assistant and deactivate it.
    3. Find Media Library Assistant and delete it. You will not lose any settings.
    4. Go to Plugins/Add New.
    5. Click “Upload Plugin”, to the right of the Add Plugins title.
    6. ”Browse…” to the location of the ZIP Archive and click on it.
    7. Click “Install Now”, to the right of “Browse…”
    8. When the install completes, click “Activate Plugin” at the bottom of the screen.
    9. When the activation completes, go back to the Plugins/Installed Plugins screen.
    10. Scroll down to “Media Library Assistant” and look for a date like “20180124” at the start of the Description. That’s how you know you have a Development Version. You can also go to the Settings/Media Library Assistant submenu and see the date stamp in the heading.

    That’s it. I don’t change the version number of the Development Version, so you will be notified when the next official version comes out and the normal update process will continue to work.

    To install the example plugin, navigate to the Settings/Media library Assistant Documentation tab and click the “Example Plugins” button. You will see a table that lists all the example plugins and gives you a “one-click” action for installing them. Type “javascript” in the text box and click “Search Plugins” to filter the table. You are looking for “MLA JavaScript Example” example plugin. Find that plugin and hover over the title in the left-most column. Click the “Install” rollover action, then go to the WordPress Plugins/Installed Plugins submenu and activate it as you would any other plugin.

    Once the example plugin is installed and activated you can display the full caption under the lightbox by adding this parameter to your [mla_gallery] shortcode:

    mla_link_attributes='mla-caption="{+post_excerpt,attr+}"'

    Note carefully the single quotes surrounding the parameter and the double quotes surrounding the parameter value.

    It would be great if you can install the Development Version and new example plugin and let me know how they work for you. Thanks for inspiring an interesting new example plugin.

    Thread Starter customle

    (@customle)

    I installed the new plugin and example plugin, and it took some experimenting but it works perfectly now, thank you. See example here:
    https://brockmansigns.com/vehicle-graphics/trailer-graphics/

    When I first added the above it did not work because I thought this was to be in place of my original code
    mla_caption=”{+post_excerpt,substr(0,20)+}…”
    Then I looked in the comments in the example plugin php, which says to add this:
    mla_link_attributes=’data-featherlight=”image” mla-caption=”{+post_excerpt,attr+}”‘
    which also did not work.

    So then I tried this:
    [mla_gallery mla_link_attributes=’mla-caption=”{+post_excerpt,attr+}”‘ link=”file” mla_caption=”{+post_excerpt,substr(0,20)+}…” size=”150-cropped” ids=”943,941,1254,1256,1255,1214,942,718,717,716,670,713,712,669″]
    and it worked perfectly.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for taking the time to install the example plugin and confirm that it does what you need. I regret any confusion caused by my explanation about adding the mla_link_attributes parameter to your shortcode.

    As you discovered, the new parameter is in addition to the other parameters required for your application. The original mla_caption parameter still displays the abbreviated caption under the gallery thumbnails. The new parameter adds the full caption to the links behind the thumbnails. The full caption is copied below the lightbox display by a bit of JavaScript code added by the example plugin.

    I am leaving this topic resolved. Thanks for working with me on this new example plugin.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘limit caption length’ is closed to new replies.