Skip to content

Instantly share code, notes, and snippets.

@macariojames
Last active August 1, 2019 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macariojames/655c760d13ece75a40c8114cef996257 to your computer and use it in GitHub Desktop.
Save macariojames/655c760d13ece75a40c8114cef996257 to your computer and use it in GitHub Desktop.
Wordpress: register and enqueue of scripts, use wp_localize_script to get current theme images
// for the JS file that needs theme images
// append rest of directory
// could add multiple variables if wanted inside array
// ~mj
wp_localize_script(
'main', // $handle
'WPURLS',
array(
'siteurl' => print_dir('images') // instead of custom function print_dir(), you can put the path of your images directory
)
);
// the gist for my custom print_dir() function used above:
https://gist.github.com/macariojames/fced3f8bc6bb65634ea4a642c6f4e571
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment