Support

Account

Home Forums General Issues Trimming words from a field Reply To: Trimming words from a field

  • No idea if this would work but…

    Convert your function to a custom shortcode:

    function project_excerpt() {
    	global $post;
    	$text = get_field('Objetivos');
    	if ( $text ) {
    		$text = strip_shortcodes( $text );
    		$text = str_replace(']]>', ']]>>', $text);
    		$text_length = strlen($text); // Get text length (characters)
    		$excerpt_length = 50; // 50 desired characters
    		$excerpt_more = '…';
    
    		// Shorten the text
    		$text = substr($text, 0, $excerpt_length);
    
    		// If the text is more than 50 characters, append $excerpt_more
    		if ($text_length > $excerpt_length) {
    			$text .= $excerpt_more;
    		}
    
    	}
    	return apply_filters('the_excerpt', $text);
    }
    add_shortcode('custom_acf_excerpt', 'project_excerpt');  

    You can then either call it as code:
    <?php echo do_shortcode("[custom_acf_excerpt]"); ?>

    Or as a shortcode in the editor:
    [custom_acf_excerpt]

    Code is untested