0

I'm using the following snippet to automatically break a too long post into multiple pages

function filter_more_with_nextpage( $content ){

    $content = str_replace( '<!--more-->', '<!--nextpage-->', $content );
    $content = preg_replace( '/<!--nextpage-->/i', '<!--more-->', $content, 1 );

    return $content;
}
add_filter( 'content_save_pre', 'filter_more_with_nextpage' );

works like a charm, but I'd like to add automatically a link <a> element before the page break to help directing users to the following page.

I don't wish to put the link in the post content manually (from wp backend) nor have it inserted automatically in the post content (I don't want it saved along the post itself). Rather, I'd wish to have it generated just before <!--nextpage--> tag breaks the current page.

  • From above code, where's the problem with inserting that anchor/link tag? – kaiser Jun 23 '13 at 12:06
  • the filter is for content_save_pre and will convert via regex the more tags after the first one, if I add more filtering to content_save_pre it will be saved inside the post which I don't want; I think I like most the Krzysiek idea, very simple :) – unfulvio Jun 23 '13 at 15:06
1

If you use <!--nextpage--> tag, then you could use wp_link_pages function. Just put it in your single.php template.

  • thanks! this is simple and effective! silly me for not having thought of it :) – unfulvio Jun 23 '13 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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