I made a WordPress plugin to generate random codes

Here is my script. Zip it and upload to wordpress

<?php

/*

Plugin Name: Random Number Generator

Description: Generates a random number string in the format XXX-XXXXXX-XXXX and provides a Method 2 button.

Version: 1.0

Author: Your Name

*/

function random_number_generator_shortcode() {

$random_number = generate_random_number();

$method_2_link = '<a href="https://example.com" target="_blank" class="method-2-button">Method 2</a>';

return '<div class="random-number-generator">' . $random_number . '</div>' . $method_2_link;

}

function generate_random_number() {

$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';

$random_string = '';

for ($i = 0; $i < 4; $i++) {

$random_string .= $characters[rand(0, strlen($characters) - 1)];

}

$random_string .= '-';

for ($i = 0; $i < 5; $i++) {

$random_string .= $characters[rand(0, strlen($characters) - 1)];

}

$random_string .= '-';

for ($i = 0; $i < 5; $i++) {

$random_string .= $characters[rand(0, strlen($characters) - 1)];

}

return $random_string;

}

add_shortcode('random_number_generator', 'random_number_generator_shortcode');

function random_number_generator_enqueue_styles() {

wp_enqueue_style('random-number-generator-style', plugins_url('style.css', __FILE__));

}

add_action('wp_enqueue_scripts', 'random_number_generator_enqueue_styles');

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *