Code Snippets v3 Pro will be adding much better support for working with Elementor, but in the meantime, you can add your code as a shortcode like so:
add_action( 'display_ref_number', function () {
$output = 'generate output here';
return $output;
} );
And then you just use [display_ref_number]
in an Elementor widget.
Thread Starter
jrweb
(@jrweb)
Thank you @bungeshea! So where exactly would I add my own code? It looks like this and creates a random string containing 10 random characters.
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
echo generateRandomString();
-
This reply was modified 1 year ago by jrweb.
You could combine them like this:
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
add_action( 'display_ref_number', function () {
$output = generateRandomString();
return $output;
} );
Thread Starter
jrweb
(@jrweb)
@bungeshea I added it as a snippet and inside my form I added [display_ref_number] in both email and email 2. However this doesn’t print the string it only prints “[display_ref_number]”. Am I doing something wrong? Is there a shortcode I can use inside the form that creates the string?
Ah, I missed that you were using a form widget. Is this one of the core Elementor widgets?
Thread Starter
jrweb
(@jrweb)
@bungeshea Yes it is Elementors widget form!