WPChill / modula-lite

https://wordpress.org/plugins/modula-best-grid-gallery/
GNU General Public License v3.0
18 stars 9 forks source link

Clip/trim la caption afisat in galerie #990

Closed andrei-l-cristea closed 1 month ago

andrei-l-cristea commented 3 months ago

Sa poti configura din modula o limita de caractere pentru caption-ul afisat in listarea generala. Cand deschizi o imagine in lightbox sa fie afisat tot caption-ul.

cristianraiber commented 3 months ago

As pune un filtru, sa nu mai adaugam inca onsetare

TeoAlex commented 1 month ago

There is no need to add another filter for this. We have a larger filter where we can modify the description (only on hover, not the caption).

Add one of these functions, for example, in wp-content/themes//functions.php

  1. Limits the number of characters at 55 characters. add_filter( 'modula_shortcode_item_data', 'modula_max_length_hover_description', 100 ); function modula_max_length_hover_description( $item_data ) { $max_length = 55; if( isset( $item_data['description'] ) && '' != $item_data['description'] && strlen( $item_data['description'] ) > $max_length ){

    $item_data['description'] = substr( $item_data['description'], 0, $max_length );

    }

    return $item_data; }

  2. Limits number of words at 55 words. add_filter( 'modula_shortcode_item_data', 'modula_max_words_hover_description', 100 ); function modula_max_words_hover_description( $item_data ) { $max_words = 55;

    if ( isset( $item_data['description'] ) && '' != $item_data['description'] ) {

    $words = explode(' ', $item_data['description']);
    
    if (count($words) > $max_words) {
        $item_data['description'] = implode(' ', array_slice($words, 0, $max_words));
    }

    }

    return $item_data; }