The conversion from text with <!--nextpage-->
into "pages" happens in setup_postdata
. But the hook you use executes when the template tag with the same name, the_content
is called. So what this means is you have to change the content before the loop starts. It can be a bit tricky. Off the top of my head I don't know of any suitable hooks but you can check the source code for setup_postdata
and there might be one. In the theme, though, you can access $posts
so if you put this in a template, it should work:
global $posts;
array_map( function( $apost ) {
$apost->post_content = $apost->post_content.'<!--nextpage-->'.$apost->post_content;
return $apost;
}, $posts );
If you don't have PHP version => 5.3 you can't use anonymous functions. In that case, this version will work:
global $posts;
function output( $apost ) {
$apost->post_content = $apost->post_content.'<!--nextpage-->'.$apost->post_content;
return $apost;
}
array_map( 'output', $posts );