Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #581853

    Hi there,

    Is there a way to limit the Post Title length on the Magazine element?

    We have some quite long titles and we can’t shorten them, for internal reasons.

    Thanks!

    #582843

    Hey worldfuturecouncil,

    I’m not sure I understand what you mean by that, could you try to explain a bit further please? A link to the site in question and/or a screenshot might help us understand better as well.

    Best regards,
    Rikard

    #582845

    Hey worldfuturecouncil!

    Thank you for using Enfold.

    Please provide the link to the page with the magazine element. You can use this in the functions.php file:

    //limit string
    function limit_text($text, $limit) {
    	if (str_word_count($text, 0) > $limit) {
    	  $words = str_word_count($text, 2);
    	  $pos = array_keys($words);
    	  $text = substr($text, 0, $pos[$limit]) . '...';
    	}
    	return $text;
    }
    
    //configure title
    add_filter('the_title', 'the_title_mod', 10, 2);
    function the_title_mod($title, $ids) {
    	if (is_page('ID HERE')) {
    		$title = limit_text($title, 5);
    	}
    
    	return $title;
    }

    Adjust the value of the is_page conditional function. https://developer.wordpress.org/reference/functions/is_page/

    Best regards,
    Ismael

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.