You can’t use wp_localize_script
with jquery. this function use the WP_Scripts::localize()
function which have a condition right in the start.
You can see it in the file \wp-includes\class.wp-scripts.php line 414
if ( $handle === 'jquery' )
$handle="jquery-core";
You can do something else like add the script with other action like wp_head
if your script is in the <head>
or wp_print_footer_scripts
if its in the footer.
add_action('wp_enqueue_scripts', function () {
wp_dequeue_script('jquery');
wp_deregister_script('jquery');
wp_register_script('jquery', get_stylesheet_directory_uri() . '/build/scripts/app.js');
wp_enqueue_script('jquery');
});
add_action('wp_head', function() {
global $wp_query;
$my_object = array(
'ajaxurl' => admin_url('admin-ajax.php'),
'query_vars' => json_encode($wp_query->query),
'is_search' => is_search(),
'current_page' => get_query_var('paged') ? get_query_var('paged') : 1,
'max_page' => $wp_query->max_num_pages,
);
?>
<script>
var ajaxpagination = <?php echo wp_json_encode($my_object); ?>
</script>
<?php
}, 0, 1);