WordPress Code Snippets

A fresh mix of code snippets and tutorials

Limit Characters in WordPress Navigation Links


Here is are two jQuery techniques to limit the number of characters in a string, applied to WordPress navigation links.

Limit Characters in Both Nav Links

Add the following to your theme’s JavaScript file (or via settings or whatever):

This assumes that your template code looks like this:

In the jQuery snippet, make sure to change the value of n to the maximum number of characters. You can also change the ellipses, ..., or remove it entirely.

Limit Characters in Either Nav Link

The previous snippet limits characters in both the previous and next navigation tags. To only limit characters in one or the other (or both), consider the following code:

This will limit both previous and next links to 50 characters. Edit either 50 to suit your needs. Note that for this snippet to work, we need to add a .prev and .next class to each nav link. Here is one way to do it:

These WP tags display nav links for single post views. The same general technique can be used to limit characters for index/archive navigation, just change the tags and done.

Learn more

WordPress Themes In Depth

Show Support

Like our new Facebook Page to show support!