Skip to content

Instantly share code, notes, and snippets.

@felipelavinz
Created June 23, 2016 00: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 felipelavinz/6ea32b71053997f99f478741ff0e0e26 to your computer and use it in GitHub Desktop.
Save felipelavinz/6ea32b71053997f99f478741ff0e0e26 to your computer and use it in GitHub Desktop.
<?php
/**
* Esto puede ser parte del archivo functions.php de tu tema
*/
add_action('wp_enqueue_scripts', 'custom_enqueue_scripts');
function custom_enqueue_scripts(){
// encolar el script
wp_enqueue_script('mycustomscript', get_stylesheet_directory_uri() .'/js/myscript.js', array('jquery'), '1.0', true);
/**
* Definir variables de localización
* Luego, dentro de tu js puedes llamar a Foo.ajaxurl y tendrá la URL de admin-ajax.php
*/
wp_localize_script('mycustomscript', 'Foo', array(
'ajaxurl' => admin_url('admin-ajax.php')
));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment