How to insert text between the page numbers?

Inside my article I use the tag !--nextpage--. Now how to insert text between the page numbers. In HTML it should look like this:

div class="postlink"
p style="text-align: center;"my test 1/p

a rel="nofollow" href="https://domen.com/linkpost/2/" 2 /a
a rel="nofollow" href="https://domen.com/linkpost/3/" 3 /a
a rel="nofollow" href="https://domen.com/linkpost/4/" 4 /a
a rel="nofollow" href="https://domen.com/linkpost/5/" 5/a

p style="text-align: center;"my text 2/p

a rel="nofollow" href="https://domen.com/linkpost/6/" 6 /a
a rel="nofollow" href="https://domen.com/linkpost/7/" 7 /a
a rel="nofollow" href="https://domen.com/linkpost/8/" 8 /a

p style="text-align: center;"my text 3/p

a rel="nofollow" href="https://domen.com/linkpost/9/" 9 /a
a rel="nofollow" href="https://domen.com/linkpost/10/" 10/a
a rel="nofollow" href="https://domen.com/linkpost/11/" 11 /a
/div

Topic nextpage wp-link-pages Wordpress

Category Web


If you're using wp_link_pages() with 'next_or_number' set to 'number' (or not set at all, it's the default), which you presumably are, then you can use the wp_link_pages_link filter.

wp_link_pages_link lets you filter the HTML for each individual page link that's output. The 2nd argument, $i, gives you the page number. You can use this to conditionally output HTML before or after the link depending on the current page number.

For example, if I wanted to output a <br> tag after the second link, I would do this:

function wpse_296614_page_link( $link, $i ) {
    if ( $i === 2 ) {
        $link = $link . '<br>';
    }

    return $link;
}
add_filter( 'wp_link_pages_link', 'wpse_296614_page_link', 10, 2 );

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.