2

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>
1

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 );
  • So I use wp_link_pages() , but the text I need to insert between pages a few times, so it's not suitable, because there you can only print it once, after a certain page – Namor Chavoloh Mar 13 '18 at 17:51
  • Well it's the only way to do it, so it is suitable. Just change the condition. You could use $i %2 === 0 to check if the current page is even numbered, for example. Or you could add multiple conditions and it will output if any of them are true. There's plenty of ways to use this to do what you want. – Jacob Peattie Mar 13 '18 at 23:44
  • Thank you. They helped to find a solution, but not completely, just can not figure out how to specify after which page number to output the text. Can you know what you need to add to this code? wordpress.stackexchange.com/a/296987/138114 – Namor Chavoloh Mar 16 '18 at 8:41
  • 1
    I’ve explained it. Check the value of $i. – Jacob Peattie Mar 16 '18 at 9:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.