Advanced Post Pagination with AJAX

Implement AJAX-based pagination for posts.

<?php
function ajax_pagination_script() {
    ?>
    <script type="text/javascript">
    jQuery(document).ready(function($) {
        $(document).on('click', '.pagination a', function(e) {
            e.preventDefault();
            var link = $(this).attr('href');
            $.get(link, function(data) {
                $('.post-list').html($(data).find('.post-list').html());
                window.history.pushState(null, null, link);
            });
        });
    });
    </script>
    <?php
}
add_action('wp_footer', 'ajax_pagination_script');
?>

Post Comment