Support » Plugins » Hacks » Overriding _wp_link_page to compensate for lacking more_file parameter

  • Hi there,

    I am using the <!–nextpage–> tag on a WP page. This works fine apart from one wee problem – the URL of the page in question has a URL parameter ?language=1 appended to it and this is not passed on by the wp_link_pages code to the more page links.

    For example, the page /news?language=1 produces the links /news, /news/2/ and /news/3/ at the bottom of the page, dropping the URL parameter.

    Ok, I said to myself when I discovered the problem, I’ll just use the more_file parameter as described here (I am using a child theme with my own custom and controllable call to wp_link_pages) with some additional PHP that programmatically sets the links. However, on trying this, I couldn’t get the more_file parameter to work.

    I ended up resorting to perusing the code for wp_link_pages(), only to find out that the more_file parameter is not defined or used, yet remains in the documentation!

    So, it looks like I will have to end up customising _wp_link_page(), the helper function to wp_link_pages(), to modify the link strings. However this function isn’t pluggable. Is there any way I can override it in my child function without having to edit core WP itself. Or, is there another way to achieve what I want to do (i.e. automatically add the required parameter to the more page links)?

    Many thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • An update. For those who were thinking of using the more_file parameter, it was removed from the wp_link_pages() function in 2009. I’ve removed the reference to it from the wp_link_pages() codex page.

    Also, it turns out that _wp_link_page(), the helper function that constructs an individual link URL for the more page links, is private and so it looks like I can’t override it in my child theme functions.php. So, unless I can come up with another solution, I am either going to have to (a) modify core WP and beware every time I carry out an update to core; or (b) have it that foreign language visitors to my site revert to English pages (the default) when they want to view subsequent pages on a page containing <!–nextpage–> and have to re-click on the language change tab to see the page in their language.

    Virtually everyone offers the advice “don’t edit the core WP files!”. But sometimes it appears that WP doesn’t give you a choice. Shouldn’t we be able to override any WP core function that we desire in our functions.php, no matter where it is? Just my tuppence worth. 🙂

    Final update. Because I make the call to wp_link_pages() from within my child theme page template file, I was able to copy wp_link_pages() and _wp_link_page() from core to my child theme functions.php and give them different names. I then edited my new version of _wp_link_page() to check for the language string and pass it on.

    The disadvantage of this is that I’m taking core out of the loop for these important functions, meaning that when they are updated in the future, I won’t be able to take advantage of those changes unless I notice them and copy the changed files to my functions.php. Rather unsatisfactory, but on the other hand it now works as I wanted.

    Thank you for listening. You’ve been a lovely audience. 😉

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Overriding _wp_link_page to compensate for lacking more_file parameter’ is closed to new replies.