'Pagebreak using wp_link_pages in Wordpress

I have a php script that reads a text file of 10000 urls one in each line. The script displays all the urls in a blog post. I want the page to be divided into 10 small pages to facilitate comfortabe browsing. So how to add a pagebreak using <?php wp_link_pages(); ?> function inside a post? Something like this:

<?php
echo "Hi, This is First Page";

wp_link_pages();  

echo "Hi, This is Second Page";
?>


Solution 1:[1]

That isn't how wp_link_pages(); works. It only displays your the_content in pages if your the_content contains this tag <!--nextpage-->

sudo code

<?php
echo apply_filter ("the_content" , "Hi, This is First Page<!--nextpage-->Hi, This is second Page");
wp_link_pages(); 
?>

You might want to check out this question as to how to retain the page data if you are creating your own page content and not using the standard content area.

Wordpress PHP - need to retain nextpage paginating tag in custom query

Solution 2:[2]

When already in a php block, you can execute a function without opening another php block. According to the documentation, wp_link_pages(); should also be called without echo.

wp_link_pages();

Documentation:
https://codex.wordpress.org/Function_Reference/wp_link_pages

Solution 3:[3]

This works just fine:

global $post;
$total = substr_count($post->post_content, '<!--nextpage-->') + 1;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2
Solution 3 MikeyMo