Can anyone help me fixing this code as I am having problem creating pagination using WP_query

I have use the code that i have mentioned but still i am having problems. I don’t know whether the code is not working or might be i am doing something wrong. Can anyone advice me what to do as i have found the code on https://www.wpblog.com/use-wp_query-to-create-pagination/

<?php
get_header(); ?>
 
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
  'posts_per_page' => 4,
  'paged' => $paged
);
$custom_query = new WP_Query( $args );
?>
          <!----start-------->
<div class="wrap">
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
 
<?php
   while($custom_query->have_posts()) :
      $custom_query->the_post();
?>
       <div>
        <ul>
         <li>
           <h3><a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></h3>
        <div>
          <ul>
        <div><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a></div>
          </ul>
          <ul>
        <p><?php echo the_content(); ?></p>
          </ul>
        </div>
        <div>
          </li>
        </ul>
          </div> <!-- end blog posts -->
       <?php endwhile; ?>
      <?php if (function_exists("pagination")) {
          pagination($custom_query->max_num_pages);
      } ?>
</main><!-- #main -->
</div><!-- #primary -->
</div><!-- .wrap -->
          <!----end-------->
<?php get_footer();

Using a plugin like WP Page Navi could me a lot easier, I think. Please try to follow the solution posted in this discussion.

Regards,
Kharis

But if i want to do that manually then what should be the right way to do that ?

I am sorry, that’s really a complex task to do as it requires code testing. Since it really goes beyond our support service policy, nothing we can do. Thank you for your understanding.

Regards,
Kharis