Archived topic
Online editor for "functions.php" does not work as expected
3 replies · Started by Oliver on August 23, 2019
Hi, I am trying to add the below to "functions.php" using the online editor:
add_shortcode(‘get_random_num’, ‘generate_random_number’);
function generate_random_number() {
return strval(rand(0, 999));
}
The error message is: Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP.
Any ideas if this should work?
Thanks,
Oliver
Hi there,
Make sure you aren't using the wrong quotation mark:
add_shortcode('get_random_num', 'generate_random_number');
function generate_random_number() {
return strval(rand(0, 999));
}
I tested this code in Code Snippets and didn't get any warnings:
https://docs.generatepress.com/article/adding-php/
Also make sure you are not adding this to the parent theme's function.php either.
argh... the quotation mark!
Thanks,
;-0liver
No problem :)