This is a self Q&A.
Often in WordPress you use the page hierarchy to build out project structure. For example, when doing portfolio sites, this is common:
- Work
- BMW
- Models
- 3-series
- 5-series
- Models
- Audi
- Models
- A3
- A4
- Models
- BMW
So, when the user is on the 3-series page, often you’d like to have a link to the “Next car manufacturer”. How can you do that without a plugin?
These functions allow you to set the depth you want to use to determine the next page. So in the question, the user was on ‘3-series’, so the depth would be 2. So, the link returned would be to the “Audi” page.
It’s used like this in your template (my example is using an image for the link text):
And place this in functions.php: