currently, using <!--nextpage-->
on a post pulls just numbers. What I would like is to be able to name each page break, and then call the name instead of just a number. Something like:
<!--nextpage: Introduction-->
I’m not talking about url renaming, just names to be used for the page links.
Can anyone help?
The text for
<!--nextpage-->
is hardcoded, so you can’t modify that specifically.wp_link_pages
only works with consistent text, so I don’t think you can really make that do exactly what you want either, but it does accept a parameterecho
which you can set tofalse
to return the value. Leveraging that, there are plenty of ways to accomplish what you’re looking to do. Three easy options are to use shortcode, another HTML comment, or you could use post meta. Personally, I’d probably opt for another HTML comment, right at the top of each “page”. A post might then look like this:Solution
Add this to your functions.php file and customize it for your usage, then you can call
my_wp_link_pages()
instead ofwp_link_pages()
to get your custom links:Notes
This uses regular expressions to replace the numbers in the links with the section heading. You’re probably wondering about the
<b>
tags, right? Those are just to make sure that we identify and replace only the numbers we want to, otherwise there’s nothing for the regex to “latch onto” and there would be a significant likelihood for unpredictable behavior (e.g. a slug/juniors-1st-birthday/
might become/juniors-Introductionst-birthday/
).