[Resolved] Online editor for "functions.php" does not work as expected

Home Forums Support [Resolved] Online editor for "functions.php" does not work as expected

Home Forums Support Online editor for "functions.php" does not work as expected

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #991935
    Oliver

    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

    #991955
    Leo
    Staff
    Customer Support

    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.

    #992160
    Oliver

    argh… the quotation mark!

    Thanks,
    ;-0liver

    #992397
    Leo
    Staff
    Customer Support

    No problem 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.