Skip to content

Instantly share code, notes, and snippets.

@websupporter
Created September 3, 2016 06:59
Show Gist options
  • Save websupporter/bce2ff5a23e56330df458a1c120b14da to your computer and use it in GitHub Desktop.
Save websupporter/bce2ff5a23e56330df458a1c120b14da to your computer and use it in GitHub Desktop.
usage of rest_url() and rest nonce
<?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