Need help using rand() with shortcode button more efficiently
-
I’m working on creating a shortcode button that can generate a random link in a more user friendly way. Below is what I currently have and it does function with the user input this way:
[btnrandom min="23" max="46" text="Go somewhere with a random value from 23 to 46"]and the code for the shortcode is as follows:
function ac_buttonrandom( $atts ) { extract( shortcode_atts( array( 'min' => '', 'max' => '', 'text' => 'Continue', ), $atts ) ); $randompage = rand($min, $max); return " <div class='tease-button tease-button-random'><a href='#$randompage'>$text</a></div> "; } add_shortcode( 'btnrandom', 'ac_buttonrandom' );What I would like is for the shortcode to function more like this:
[btnrandom random="23, 46" text="Go somewhere with a random value from 23 to 46"]However a single value doesn’t seem to work with rand(); properly. I’m sure this is a simple fix and I’m a beginner when it comes to php.
Thanks!
The topic ‘Need help using rand() with shortcode button more efficiently’ is closed to new replies.