using globals from wp_link_pages function

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

Topic wp-link-pages globals Wordpress

Category Web


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.