Since wordpress does not have a menu icon (aka “user friendly) way to add the command to a post or page, I’m trying to create a shortcode to do it.
However, as logic would have it, its not that easy. Doing this with a shortcode merely inserts into the markup, which is post process, not pre-process as wordpress does it substitution in pre-process.
Can anyone shed light on how this can be done?
Best solution for what you want to accomplish which is essentially to make the next page feature more user friendly for your authors is to add a TinyMCE button that will do this for you. This may be a bit complicated so hold your hat. To avoid this answer being the length of a thesis, I have added comments in all codes to help you understand what each function does and I highly recommend that you read and thoroughly understand them.
Firstly, in your theme folder, add a folder named
admin
and inside it, create fileclass.new_tinymce_btn.php
with code:This code will add custom buttons to the visual editor.
Next, in your theme folder, create these folders
adminjs/buttons
and inside, create this JS filenextpage.js
with code:You will need to add an image for the button (
/images/btn_nextpage.png
). The above code is a rather simple javascript function for what happens when the button is pressed.Now you will need to load this button class by adding this to your functions file:
To make this issue even more complicated, if you are in the visual editor and
<!--nextpage-->
is added in by Javascript in the html/text, it will not appear visually for you until you have refreshed the page or updated it. This can of course be confusing for your users that cannot see visually where the separation is until a refresh, therefore, I have added this shortcode[next_page_button]
to the mix. It will be added when you click the button.So you may ask, what does it do? Well let’s determine that. Add this code in your functions:
Pay attention to
return ''
. It does nothing! So it is only a dummy shortcode to add a visual separate for the user.Here is an alternate technique for adding a button to the wordpress editor TinyMCE for inserting
<!-- next-page -->
following the<!-- more -->
button. This code uses themce_buttons
filter to insert thewp_page
button right after the existingwp_more
button.Add to functions.php :
See also http://codex.wordpress.org/TinyMCE_Custom_Buttons
one-liner-ish from comments: