Is it possible to automatically add the <!--nextpage-->
quicktag after X number of paragraphs?
My client isn’t exactly tech savvy so I’m trying to find a way to help them break up their enormous pages without them having to come back to me time and time again asking how to do it.
The concept
Adding something to the content during saving and considering all sorts of possible MarkUp isn’t an easy task. I played around a bit with it and decided that the best chance would be to use PHP native
DOMDocument
class to parse the content, identify the paragraph and add the HTML comment to it. This is much more reliable than using Regular Expressions and much better performance wise.Adjusting the plugin
First, the plugin uses Dependency Injection to decouple the classes. If you need to alter the output (change the number of paragraphs, insert some other comment like a line break or something from a shortcode, etc.), you’ll need to jump in and adjust the arguments for the
Parser
class that is initialized from inside theController
.If you want to insert some normal HTML (for example an ad after the X paragraph), then you’ll need to go into the
Parser
and remove the following line:and then replace the
$comment
in the next line with$this->tag
. Then you can throw in normal HTML tags, text or whatever.For more complicated stuff, you’ll need to utilize the
DOMDocument
and similar object methods. Please refer to php.net for further information.Notes
The following plugin only works with PHP 5.3+. If you got an earlier version, it simply won’t activate and instead show you a WP die screen.
The plugin