Search
 
SCRIPT & CODE EXAMPLE
 

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' );
Comment

wp_localize_script

<?php
function pw_load_scripts() {
 
	wp_enqueue_script('pw-script', plugin_dir_url( __FILE__ ) . 'js/pw-script.js');
	wp_localize_script('pw-script', 'pw_script_vars', array(
			'alert' => __('Hey! You have clicked the button!', 'pippin')
		)
	);
 
}
add_action('wp_enqueue_scripts', 'pw_load_scripts');
Comment

PREVIOUS NEXT
Code Example
Php :: php disable buutton 
Php :: export to excel in php 
Php :: wp order archive page post by title 
Php :: how to set select option value dynamically in php 
Php :: laravel get data from request 
Php :: laravel enable mysql logging 
Php :: php get char from string position 
Php :: php add variable to array 
Php :: date time format php 
Php :: laravel database seeder 
Php :: copy php array to another 
Php :: a php session was created by a session_start() 
Php :: woocommerce_order_status_changed add action 
Php :: Laravel 8 Pagination Ui Problem 
Php :: laravel eloquent multiple join with where conditions 
Php :: php regex replace to remove special characters and accented 
Php :: storepublicly laravel 
Php :: declare variable in php class 
Php :: php clear post data 
Php :: laravel factory relations data 
Php :: fillable property to allow mass assignment 
Php :: status messages wordpress settings form 
Php :: install php unzip 
Php :: laravel where null 
Php :: yajra laravel datatables rawcolumn 
Php :: symfony messenger rabbitMQ 
Php :: run laravel seeder 
Php :: how to use include in php 
Php :: Hide Categories - Woocommerce Product Page 
Php :: php wpdb foreach 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =