PHP Notice: Function is_page was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false

Question

In my functions.php I have:

// Load Google Optimize script in head
function us_homepage_optimize_test() {
    $site_id = get_current_blog_id();
    if(is_page(10) && is_main_site($site_id)) {
        wp_enqueue_script(
            'us_homepage_optimize_test',
            'https://www.googleoptimize.com/optimize.js?id=OPT-XXXXXXXX',
            array(),
            '1.0.0',
            false
        );
    }
}
add_action('wp_enqueue_scripts', 'us_homepage_optimize_test');

The Google Optimize script does not load and in debug.log I see:

PHP Notice: Function is_page was called incorrectly.
Conditional query tags do not work before the query is run. Before
then, they always return false. Please see Debugging
in WordPress
for more information.

How should I adjust my functions.php code, please?

Help appreciated.

0
Steve 2 months 2022-08-09T02:18:53-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse