Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

wp localize script

function theme_enqueue_scripts() {
    /**
     * frontend ajax requests.
     */
    wp_enqueue_script( 'frontend-ajax', JS_DIR_URI . 'frontend-ajax.js', array('jquery'), null, true );
    wp_localize_script( 'frontend-ajax', 'frontend_ajax_object',
        array( 
            'ajaxurl' => admin_url( 'admin-ajax.php' ),
            'data_var_1' => 'value 1',
            'data_var_2' => 'value 2',
        )
    );
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_scripts' );
Source by developer.wordpress.org #
 
PREVIOUS NEXT
Tagged: #wp #localize #script
ADD COMMENT
Topic
Name
5+8 =