WP/Limiting characters generated by '%link'

49 views
asked Jun 11, 2013 in Website Builder by Maria (1,020 points)
Hello
Currently I am working on a Twenty Eleven child theme, and I have some code in the loop-single-post.php that allows navigation from one post page to the next or previous ones. However there is one problem. If the title of the previous or next post is long it adds space on the top of the page. I am looking for a way to limit the characters showing in the %link.
Any suggestions will be highly appreciated
Many thanks

1 Answer

0 like 0 dislike
answered Jun 11, 2013 by WebProX (12,200 points)
Try this code
<div class="next">
<?php $your_next_post = get_next_post();
 if (!empty( $your_next_post )):
 $nexty=$your_next_post->post_title;
if (strlen($nexty) > 15){$new_short = substr($nexty,0,15).'...';}else{$new_short=$nexty;}
 endif; ?>

<?php next_post_link('%link ›', $new_short ); ?>
 </div>
...