0

I don't want my variable "infinite" to be global variable. but it's like wp_localize_script would make it global automatically. How to solve that? This is my code.

Wordpress php file:

public function infinite_scroll_js() {

    $args = array(
        'url'   => admin_url( 'admin-ajax.php' ),
        'query' => $post_title,
        'post_id' => $ID
    );

    wp_enqueue_script( 'infinite_scroll_js', /Post/js/get_infinite.js', array(), null, true );
    wp_localize_script( 'infinite_scroll_js', 'infinite', $args );
}

Then when I go the chrome devtools, 'infinite' now is a global variable. enter image description here

You know no one like global variable, I just want 'infinite' be available in 'get_infinite.js'. I just want chrome console says not defined when I type in 'infinite'.

  • What do you mean? Can you have an example of what you are looking for? – Jack Johansson Dec 5 '17 at 15:35
  • updated the question – Nobody Dec 5 '17 at 15:59
  • why you localize script in the first place ?what you trying to achieve?it mainly used to make any data available to your script that you can normally only get from the server side of WordPress. – IBRAHIM EZZAT Dec 5 '17 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.