First published on May 7, 2008
You, or someone whose blog you manage, might have the need to put long URLs in their WordPress posts. Generally speaking, if these are linked URLs, you should simply use some shorter, descriptive link text and keep the long URL in the link tag. For example, use William Hung article that I haven’t actually read instead of http://tvguide.sympatico.msn.ca/Hung+trades+music+for+mathematics/TVNews/Articles/080422_william_hung_teaches_MH.htm?isfa=1.
However, if this is not possible (you want to show the web address or you simply don’t have control over the person posting), you can use a plugin to automatically shorten the display of the URL, without altering the actual link. For example, instead of the painfully long URL above, it would display as http://tvguide.sympatico.msn.c…..htm?isfa=1.
A great plugin called wp-chunk already exists to solve this problem for URLs in comments. You can modify the plugin to apply to posts by either replacing or adding to the bottom “filter” code with this line:
For those who are scared to modify code, here is a modified version of wp-chunk (with permission from its author) for posts. I have successfully tested it with WordPress 2.5:
Simply unzip the file to your plugins folder and activate it. I have also included one extra option to add the functionality of automatically turning all non-linked URLs into links. (Look for the $wp_chunk_clickable setting in the plugin file.) For example, with this option enabled, if you were to type http://www.theblog.ca in your post, it would automatically be linked as http://www.theblog.ca.