I am having problems displaying a title excerpt on a next post link.
If the characters are more than 30 for the next posts title i would just like it to show ‘…’
This is the code I use for title excerpts
<?php short_title('...', 25); ?>
And this is the code I use for next post links
<?php next_post_link( '<span class="pn-a">%link</span>', '<span class="pn-a">%title</span>' ) ?>
Short Title Function
function short_title($after = '', $length) {
$mytitle = get_the_title();
if ( strlen($mytitle) > $length ) {
$mytitle = substr($mytitle,0,$length);
echo $mytitle . $after;
} else {
echo $mytitle;
}
}
Any help?
Thanks
Here you are 🙂
Change your function like this, remove the echo and just return the value for the title
And then in the next_post_link simply call that function
🙂