Регистрация js скрипта его подключение с AJAX
<?php
wp_enqueue_script('jquery');
add_action( 'wp_enqueue_scripts', 'project_scripts' );
function dancingsax_scripts() {
wp_enqueue_script(
'project',
get_template_directory_uri() . '/js/project.js',
array('jquery')
);
wp_localize_script('project', 'ajax', array(
'url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('ajax-nonce')
));
}
add_action('wp_ajax_pages_content', 'action_name');
add_action('wp_ajax_nopriv_pages_content', 'action_name');
function action_name() {
$text = $_POST['text'];
echo $text;
die();
}
/*
// project.js
$('body').on('click', '.class-name', function() {
var textData = 'This is text';
jQuery.post(ajax.url,
{
action : 'action_name',
nonce : ajax.nonce,
text: textData
},
function(response) {
$('.content').append(response);
});
});
*/
?>