I am using wordpress and have the following code on functions.php file
function fun1() {
wp_enqueue_script( 'aldi_code', 'wp-content/uploads/custom-css-js/675.js', array( 'jquery' ), false, true );
wp_localize_script( 'aldi_code', 'test', array(
'current_user' => wp_get_current_user()
) ) ;
}
add_action( 'wp_enqueue_scripts', 'fun1' );
I want to access the value of current_user from wp_admin through jquery using the following code
jQuery(document).ready(function( $ ){
var displayName = test.current_user.display_name;
});
The problem is that I get the error:
test is not defined.
Do you have any idea what is wrong on this code??
document.readyfunction inside thewp-content/uploads/custom-css-js/675.jsfile?jQuery(document).ready(function( $ ){ var displayName = test.current_user.display_name; });