twitter

Recent Comments

David Boyer
David Boyer January 13, 2012 at 10:05AM
Is Your CFLOOP Hogging Memory or Causing OutOfMemory Errors?

Interesting to find that out, wouldn't have expected it to be a problem. I've had similar...

baljit dhanoa
baljit dhanoa January 12, 2012 at 9:08AM
Creating A Recent Comments Widget With Disqus's API and PHP

Creating A Recent Comments Widget With Disqus's API and PHP good code pls try

Web Hosting Provider
Web Hosting Provider January 10, 2012 at 5:23PM
Creating A Recent Comments Widget With Disqus's API and PHP

Superb and very informative for me,,,

web hosting
web hosting December 2, 2011 at 7:28AM
If PHP's file_get_contents Function is Failing With IIS 7

I am new guy for this PHP. i get it clear idea about your topic.All the points are explained...

Aaron J. White
Aaron J. White November 14, 2011 at 11:54PM
Creating A Recent Comments Widget With Disqus's API and PHP

If you want to put the number of posts in a different area than the recent comments section...

Aaron J. White
Aaron J. White November 14, 2011 at 10:10PM
Creating A Recent Comments Widget With Disqus's API and PHP

It depends, are you using wordpress or joomla? I have a different plugin that checks disqus for...

Yulia Novozhilova
Yulia Novozhilova November 14, 2011 at 4:22PM
Creating A Recent Comments Widget With Disqus's API and PHP

very cool... it works! Do you know if it is possible to include number of total post likes on...

Aaron J. White
Aaron J. White October 30, 2011 at 10:40AM
Creating A Recent Comments Widget With Disqus's API and PHP

Hmm...It would probably help if I post a comment on my site so people can actually see my...

Adding a custom Prefix or Suffix to YOURLS Short URLs

Posted: November 15th, 2011 - I setup my own url shortener with YOURLS yesterday and everything seems to work perfectly. The only feature I needed that didn't seem to come OOTB is the ability to add a custom prefix or suffix to the url. My short url is http://ajwh.it, and that's good, but in order to put the icing on the cake I wanted to add the letter "e" at the beginning of all of my short urls.

It took me a second to figure out the options available to me, but after a bit of digging I came up with the process below:

**Note: The instructions below are for YOURLS v1.5

1. Install the Random Keywords plugin and activate it

I'm not going to go into the details of how to install the plugin in the post. You can find the directions for installing the plugin here: http://ajwh.it/edf2s
Note: The length of your short will end up being $ozh_random_keyword['length'] + the length of your prefix/suffix.
Also, don't forget to activate the plugin in your YOURLS admin.

2. Open functions.php and modify the yourls_rnd_string function

In the folder where you installed YOURLS open the "function.php" file located in the "includes" folder. Around line 1360 you should see the yourls_rnd_string function. If you want to add a prefix just change the value of $str in the first line of the function. So if you wanted add a prefix of ajw the beginning of your function would look like the example below.

// Generate random string of (int)$length length and type $type (see function for details)
function yourls_rnd_string ( $length = 5, $type = 0, $charlist = '' ) {
$str = 'ajw';
$length = intval( $length );

And that's it! Similarly if you want to add a suffix to all of your newly created short urls then you'll have to modify the $str variable towards the bottom of the function.

$i = 0;
while ($i < $length) {
$str .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
$str .= 'ajw';
return yourls_apply_filter( 'rnd_string', $str, $length, $type, $charlist );

If anyone knows a better way to do this please let me know. Like I mentioned I have only been using YOURLS for about a day.

P.S. If you haven't already check out the YOURLS Shortener plugin for firefox (http://ajwh.it/e3caz). It's pretty cool.


blog comments powered by Disqus