-1

I'm trying to add a Button, which generates a random URL every time it's clicked.

I found :

<a href="<?php echo ( "http://meet.jit.si/" . rand(1000, 9000) )?>" target="_blank"> click here </a>

But I have no idea where to post this into.

2
  • 2
    What's your question? Does your code not work? What doesn't it do that you need it to do? Is this related to WordPress? Aug 24, 2021 at 13:21
  • Yes, its related to Wordpress. I added a button on my website, but I have no idea, where to post this function to make it work for this button.
    – Christian
    Aug 25, 2021 at 12:57

2 Answers 2

3

It looks like your code works as written.

Alternatively, you can generate an alphanumeric string using uniqid()...

<a href="http://meet.jit.si/<?php echo uniqid()?>" target="_blank"> click here </a>

EDIT: Modified code based on additional information.

This should create a shortcode that allows you to easily add a button to a unique meeting link by adding [rand_jitsi_btn] to a post/page:

// hook our shortcode creation to `init` so that WordPress has time to initialize properly
add_action( 'init', 'add_custom_shortcode' );
function add_custom_shortcode() {
    add_shortcode( 'rand_jitsi_btn', 'create_rand_jitsi_btn' );
}
// Code to create the button
function create_rand_jitsi_btn() {
    return '<a href="http://meet.jit.si/' . uniqid() . '" target="_blank"> Launch Meeting </a>';
}

I haven't tested this code, but it should work if you place it in your child theme's functions.php file.

Note: You can use something like random_int() instead of uniqid() if you need numeric randoms.

3
  • Thank you, but where do I add this code In Wordpress?
    – Christian
    Aug 25, 2021 at 9:23
  • You'll need to provide more information about the context of your question. It's not clear what you intend to do. Aug 25, 2021 at 14:58
  • Okay: I want to create a unique jitsi-meeting-room for every visitor, who clicks on the button "create meeting room". Every visitor needs a unique URL (e.g. meet.jit.si/12345) so no visitor gets in the same meeting room. All I can do is to create a Button with a normal link - but I don't know where to give this button a function
    – Christian
    Aug 26, 2021 at 11:05
0

You could create a shortcode for the button and use that for inserting a link with a random Jitsi room anywhere in the content of your site or even in the widgets. Make the button label a variable in the shortcode so that you can further customise it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.