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 );