Web Hosting Geeks | Web Hosting Experts
Need help? Call us 1(866)TOP-HOST

14120 reviews 1680 hosting providers

Questions & Answers

WP/Limiting characters generated by '%link'

Jun 11, 2013 by Maria
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 votes
Jun 11, 2013 by WebProX
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>