Skip to main content
added 86 characters in body
Source Link
Milo
  • 78.9k
  • 4
  • 127
  • 168

Enqueue your script and use wp_localize_script to pass data.

function wpd_scripts() {
        
    wp_enqueue_script(
        'wpd_script',
        get_stylesheet_directory_uri() . '/js/script.js',
        null,
        null,
        false
    );
    
    wp_localize_script(
        'wpd_script',
        'WPD',
        array(
            'stylesheet_dir' => get_stylesheet_directory_uri()
        )
    );

}
add_action( 'wp_enqueue_scripts', 'wpd_scripts' );

You can then use WPD.stylesheet_dir in your script to get the value you set in PHP.

var marker_url = WPD.stylesheet_dir + '/assest/imgs/map/cd-icon-location.png';

Enqueue your script and use wp_localize_script to pass data.

function wpd_scripts() {
        
    wp_enqueue_script(
        'wpd_script',
        get_stylesheet_directory_uri() . '/js/script.js',
        null,
        null,
        false
    );
    
    wp_localize_script(
        'wpd_script',
        'WPD',
        array(
            'stylesheet_dir' => get_stylesheet_directory_uri()
        )
    );

}
add_action( 'wp_enqueue_scripts', 'wpd_scripts' );

You can then use WPD.stylesheet_dir in your script to get the value you set in PHP.

Enqueue your script and use wp_localize_script to pass data.

function wpd_scripts() {
        
    wp_enqueue_script(
        'wpd_script',
        get_stylesheet_directory_uri() . '/js/script.js',
        null,
        null,
        false
    );
    
    wp_localize_script(
        'wpd_script',
        'WPD',
        array(
            'stylesheet_dir' => get_stylesheet_directory_uri()
        )
    );

}
add_action( 'wp_enqueue_scripts', 'wpd_scripts' );

You can then use WPD.stylesheet_dir in your script to get the value you set in PHP.

var marker_url = WPD.stylesheet_dir + '/assest/imgs/map/cd-icon-location.png';
added 8 characters in body
Source Link
Milo
  • 78.9k
  • 4
  • 127
  • 168

Enqueue your script and use wp_localize_script to pass data.

function wpd_scripts() {
        
    wp_enqueue_script(
        'wpd_script',
        get_template_directory_uriget_stylesheet_directory_uri() . '/js/script.js',
        null,
        null,
        false
    );
    
    wp_localize_script(
        'wpd_script',
        'WPD',
        array(
            'template_dir''stylesheet_dir' => get_template_directory_uriget_stylesheet_directory_uri()
        )
    );

}
add_action( 'wp_enqueue_scripts', 'wpd_scripts' );

You can then use WPD.template_dirstylesheet_dir in your script to get the value you set in PHP.

Enqueue your script and use wp_localize_script to pass data.

function wpd_scripts() {
        
    wp_enqueue_script(
        'wpd_script',
        get_template_directory_uri() . '/js/script.js',
        null,
        null,
        false
    );
    
    wp_localize_script(
        'wpd_script',
        'WPD',
        array(
            'template_dir' => get_template_directory_uri()
        )
    );

}
add_action( 'wp_enqueue_scripts', 'wpd_scripts' );

You can then use WPD.template_dir in your script to get the value you set in PHP.

Enqueue your script and use wp_localize_script to pass data.

function wpd_scripts() {
        
    wp_enqueue_script(
        'wpd_script',
        get_stylesheet_directory_uri() . '/js/script.js',
        null,
        null,
        false
    );
    
    wp_localize_script(
        'wpd_script',
        'WPD',
        array(
            'stylesheet_dir' => get_stylesheet_directory_uri()
        )
    );

}
add_action( 'wp_enqueue_scripts', 'wpd_scripts' );

You can then use WPD.stylesheet_dir in your script to get the value you set in PHP.

Source Link
Milo
  • 78.9k
  • 4
  • 127
  • 168

Enqueue your script and use wp_localize_script to pass data.

function wpd_scripts() {
        
    wp_enqueue_script(
        'wpd_script',
        get_template_directory_uri() . '/js/script.js',
        null,
        null,
        false
    );
    
    wp_localize_script(
        'wpd_script',
        'WPD',
        array(
            'template_dir' => get_template_directory_uri()
        )
    );

}
add_action( 'wp_enqueue_scripts', 'wpd_scripts' );

You can then use WPD.template_dir in your script to get the value you set in PHP.