Title: How to make a simple Random String shortcode?
Last modified: August 24, 2016

---

# How to make a simple Random String shortcode?

 *  [noyzen](https://wordpress.org/support/users/noyzen/)
 * (@noyzen)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/how-to-make-a-simple-random-string-shortcode/)
 * Hi,
 * i want to make a shortcode which displays a random string. i found some javascripts
   which they do that… (or php is better?) but i dont know how to convert them to
   shortcodes…
 * i’m sure lot of pro people know it easily… thanks!
    here is my code: (u have 
   better idea? do it!)
 *     ```
       <script language="javascript" type="text/javascript">
       function makeid()
       {
           var text = "";
           var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
   
           for( var i=0; i < 5; i++ )
               text += possible.charAt(Math.floor(Math.random() * possible.length));
   
           return text;
       }
       </script>
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/how-to-make-a-simple-random-string-shortcode/#post-6092613)
 * Here is a simple example:
 *     ```
       function random_string_func( $atts ) {
          extract( shortcode_atts( array(
                'number' => 5,
             ), $atts ) );
          $possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
          $possible_array = str_split( $possible );
          shuffle( $possible_array );
          return implode( '', array_slice( $possible_array, 0, $number ));
       }
       add_shortcode( 'random_string', 'random_string_func' );
       ```
   
 * You might want to eliminate zero, one, l (ell), and o (oh) because they are so
   similar that they cause confusion. You could also add in special characters and
   code to ensure that at least one digit and one special character are used.
 *  [Matthew](https://wordpress.org/support/users/kidsguide/)
 * (@kidsguide)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/how-to-make-a-simple-random-string-shortcode/#post-6092614)
 * You can check out the Shortcode API codex. [https://codex.wordpress.org/Shortcode_API](https://codex.wordpress.org/Shortcode_API)

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘How to make a simple Random String shortcode?’ is closed to new replies.

## Tags

 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)
 * [string](https://wordpress.org/support/topic-tag/string/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 3 participants
 * Last reply from: [Matthew](https://wordpress.org/support/users/kidsguide/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/how-to-make-a-simple-random-string-shortcode/#post-6092614)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
