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!
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
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