• How to use PHP Data in your Javascript files for WordPress

    WordPress makes it spectacularly easy to transfer data to you javascript files if you’re unfamiliar with enqueuing scripts then please refer to my previous post. Here it goes then. Say you want to do something “fancy” like ajax calls from you js files. I’m starting to get a little off point here right now i’d like to fully explore only localization. So ajax calls will be covered in a later post (hopefully soon) You’ll need to use wp_localize_script to make data availabe to javascript. Syntax: wp_localize_script( $handle, $name, $data ); Example add_action(‘wp_enqueue_scripts’,’digthis_loadscript’); function digthis_loadscript() { wp_register_script( ‘main’, get_template_directory_uri(). ‘/js/main.js’, ”, […]

    …Read More