• Hi!

    I am trying to create a code snippet for Google Costumer Reviews for our WordPress website. This is the first few lines of the snippet:

    /**
    *   Add Google review language scripts
    */
    add_action( 'wp_enqueue_scripts', 'snippetpress_google_customer_reviews_language', 20 );
    function snippetpress_google_customer_reviews_language() {
    		$snippetpress_customer_reviews_language_script = 'window.___gcfg = {lang: \'sv\'};'; // Replace en_GB with your language
    ????????wp_register_script( 'snippetpress_customer_reviews_language_script', '', '', 'false', 'true' );
    ????????wp_enqueue_script( 'snippetpress_customer_reviews_language_script' );
    ????????wp_add_inline_script( 'snippetpress_customer_reviews_language_script', $snippetpress_customer_reviews_language_script );
    }
    

    However, when I activate the snippet, the whole website crashes with the following error message:

    “`Fatal error: Uncaught Error: Call to undefined function wp_register_script() in /home/vabbaren/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(505) : eval()’d code:7 Stack trace:
    #0 /home/vabbaren/public_html/wp-includes/class-wp-hook.php(308): snippetpress_google_customer_reviews_language()
    #1 /home/vabbaren/public_html/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()
    #2 /home/vabbaren/public_html/wp-includes/plugin.php(517): WP_Hook->do_action()
    #3 /home/vabbaren/public_html/wp-includes/script-loader.php(2180): do_action()
    #4 /home/vabbaren/public_html/wp-includes/class-wp-hook.php(308): wp_enqueue_scripts()
    #5 /home/vabbaren/public_html/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()
    #6 /home/vabbaren/public_html/wp-includes/plugin.php(517): WP_Hook->do_action()
    #7 /home/vabbaren/public_html/wp-includes/general-template.php(3043): do_action()
    #8 /home/vabbaren/public_html/wp-content/themes/flatsome/header.php(18): wp_head()
    #9 /home/vabbaren/public_html/wp-includes/template.php(783): require_once(‘/home/vabbaren/…’)
    #10 /home/vabbaren/public_html/wp-includes/template.php(718): load_template()
    #11 /home/vabbaren/public_html/wp-includes/general-template.php(48): locate_template()
    #12 /home/vabbaren/public_html/wp-content/themes/flatsome/woocommerce/single-product.php(17): get_header()
    #13 /home/vabbaren/public_html/wp-includes/template-loader.php(106): include(‘/home/vabbaren/…’)
    #14 /home/vabbaren/public_html/wp-blog-header.php(19): require_once(‘/home/vabbaren/…’)
    #15 /home/vabbaren/public_html/index.php(17): require(‘/home/vabbaren/…’)
    #16 {main} thrown in?/home/vabbaren/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(505) : eval()’d code?on line?7

    I have tried to follow the Troubleshooting guide, emptied the caches and inactivated the plugins like W3 Total Cache or Jetpack, but the error remains.

    Could you help me figure out where the issue lies?

    Many thanks,
    Aron

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Fatal error: Uncaught Error: Call to undefined function wp_register_script()’ is closed to new replies.