WordPress path url in js script file

后端 未结 5 756
北恋
北恋 2020-12-01 02:56

I added custom script:

wp_enqueue_script(\'functions\', get_bloginfo(\'template_url\') . \'/js/functions.js\', \'search\', null, false);

I

5条回答
  •  自闭症患者
    2020-12-01 03:19

        wp_register_script('custom-js',WP_PLUGIN_URL.'/PLUGIN_NAME/js/custom.js',array(),NULL,true);
        wp_enqueue_script('custom-js');
    
        $wnm_custom = array( 'template_url' => get_bloginfo('template_url') );
        wp_localize_script( 'custom-js', 'wnm_custom', $wnm_custom );
    

    and in custom.js

    alert(wnm_custom.template_url);
    

提交回复
热议问题