Created
September 3, 2016 06:59
-
-
Save websupporter/bce2ff5a23e56330df458a1c120b14da to your computer and use it in GitHub Desktop.
usage of rest_url() and rest nonce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function slug_enqueue_scripts() { | |
wp_enqueue_script( 'api-script', plugins_url( __FILE__ ) . 'script.js', array( 'jquery' ) ); | |
wp_localize_script( | |
'wp-script', | |
'wpApiSettings', | |
array( | |
'root' => esc_url_raw( rest_url() ), | |
'nonce' => wp_create_nonce( 'wp_rest' ) | |
) | |
); | |
} | |
add_action( 'wp_enqueue_scripts', 'slug_enqueue_scripts' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment