Paginated pages are showing correct content but pagination links are not

I am using a custom WP_Query to display posts on static front page. and generating numbered pagination links with paginate_links functions. This is the code I have…

$latest_args = array(
    'post_type' => 'post',
    'category__not_in' => array( 3 ),
    'ignore_sticky_posts' => 1,
    'paged' => $paged,
);

$latest_query = new WP_Query( $latest_args );

if ( $latest_query->have_posts() ) :

    while ( $latest_query->have_posts() ) : $latest_query->the_post();
        get_template_part( 'content', get_post_format() );
    endwhile;

    if ( $latest_query->max_num_pages > 1 ) :
        $big = 999999999;
        echo '<div class="pagination">';
        echo paginate_links( array(
            'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
            'format' => '?paged=%#%',
            'current' => max( 1, get_query_var('paged') ),
            'total' => $latest_query->max_num_pages
        ) );
        echo '</div>';
    endif;

endif;

wp_reset_postdata();

But when I use this on my static front page then it always show first page content on all other pages too. But it was corrected by adding paged parameter to query as suggested in codex.

if ( get_query_var('paged') ) {
  $paged = get_query_var('paged');
} elseif ( get_query_var('page') ) {
  $paged = get_query_var('page');
} else {
  $paged = 1;
}

Which fixed the duplicate content on paginated pages but number based pagination links are always stick to first page. It always displays first link (1) as current which makes difficult to browse rest of the pages.

Although this code works fine if I use it on any other page except static front page.

Any solution to this issue.

EDIT: Update

I have tried disabling all plugins and removed all custom developed functions from functions.php but the problem still exists. So I am guessing this has to do something with how I am using WP_Query or paginate_links function.

There should be some mistake in this code.

Solutions Collecting From Web of "Paginated pages are showing correct content but pagination links are not"

Static pages doesn’t work with paged query variable, they need the page variable.

This is the reason why your second code block makes the query work: it uses the page var when available.

However, your paginated links code always use paged:

...
'format' => '?paged=%#%',
...

So you are sending paged query var but looking for page var.

Solution is to make your format argument send page query var if used from a static page.

if ( $latest_query->max_num_pages > 1 ) :

    $var = is_page() ? 'page' : 'paged'; // <-- choose var here   

    $big = 999999999;
    echo '<div class="pagination">';
    echo paginate_links( array(
        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),

        'format' => '?' . $var . '=%#%', // <-- use var here  

        'current' => max( 1, get_query_var($var) ), // <-- use var here 
        'total' => $latest_query->max_num_pages
    ) );
    echo '</div>';
endif;

Untested.