Add “Trim Title” Option to the Blog Grid Page Builder Module
// Add new setting to the blog grid module to enable trim titles (new setting will be added to the Title tab)
add_action( 'vc_after_init', function() {
$settings = array(
'type' => 'vcex_ofswitch',
'heading' => esc_html__( 'Trim The Title', 'total' ),
'param_name' => 'trim_title',
'value' => 'false',
'group' => esc_html__( 'Title', 'total' ),
);
vc_add_param( 'vcex_blog_grid', $settings );
} );
// Trim blog grid titles based on setting (change "2" to the number of words you wish to display)
add_filter( 'vcex_shortcode_loop_atts', function( $atts, $module = '' ) {
if ( 'vcex_blog_grid' == $module && isset( $atts['trim_title'] ) && 'true' == $atts['trim_title'] ) {
$atts[ 'post_title' ] = wp_trim_words( $atts[ 'post_title' ], 2, '…' );
}
return $atts;
}, 10, 2 );
All PHP snippets should be added via child theme's functions.php file or via a plugin (we recommend Code Snippets)