Примерно так
На клиенте:
jQuery.getJSON(alaxMenu.URL, alaxMenu.params, function(resp) {
if (resp.success === true) {
jQuery('menu').append(resp.data);
}
});
в function.php
wp_localize_script('views-counter', 'alaxMenu', array(
'url' => admin_url('admin-ajax.php'),
'params' => array(
'action' => 'ajax_menu',
'_ajax_nonce' => wp_create_nonce('ajax_menu_nonce'),
)
));
function get_ajax_menu( $post_object ) {
check_ajax_referer('ajax_menu_nonce');
wp_send_json_success(wp_nav_menu( array(
'theme_location' => 'ajax_load',
'container' => false,
'echo' => false,
'items_wrap' => false
) ));
}
add_action('wp_ajax_get_ajax_menu', 'get_ajax_menu');
add_action('wp_ajax_nopriv_get_ajax_menu', 'get_ajax_menu');