I'm following this reference page for wp_link_pages:https://developer.wordpress.org/reference/functions/wp_link_pages/

In it, 4 global variables are declared: $page, $numpages, $multipage, $more. I'm able to access it in my templatexxxx.php by doing this:

global $numpages;
global $page;

echo $numpages;
echo $page;

My question is this: should I be doing this? I have been taught that using/accessing global is bad. But short of coding an entire function (which seems to be a bit overkill), this seems to be the fastest and easiest way to obtain the current page and the total number of pages. Unless there's another function in the core that already does this? :S

1 Answer 1


I think I figured it out. Most of Wordpress is based on global variables. Even the main loop is pulling a giant global variable. So I guess it's ok since I'm not modifying the actual values here - just pulling it out. It might not be a bad idea to throw $numpages and $page into new variables and then call those new variables to prevent accidental modification of their global versions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.