Support » Developing with WordPress » Accessing Global Values wp_link_pages

  • Resolved L D


    Hello, under the function wp_link_pages, there are 4 global values declared:

    function wp_link_pages( $args = '' ) {
        global $page, $numpages, $multipage, $more;

    I have two questions:
    1) How do I access $page and $numpages? I want to get these values to further customise my single.php and page.php.
    2) Is it bad practice to access the global values even if I am not modifying them but simply printing them in plain text (assuming they can be accessed)?

    Hoping someone can shed some light on this!

Viewing 3 replies - 1 through 3 (of 3 total)
  • L D


    Ok, I figured out my first question. To access the global variables, you simply do the following in your single.php or similar:

    global $numpages;
    global $page;
    echo $numpages;
    echo $page;

    So I guess the only question is whether this is good practice or not and whether there are security concerns or not?

    Moderator bcworkz


    Sure, doing that is fine. That is in part why they were declared global — easily retrieved from within any scope. I cannot imagine any security concerns by outputting the values. In this case I believe they are merely numbers of no consequence.

    In some cases a global could contain sensitive information. For instance, the global $post object could be a private post that should not be shown to just anyone. You cannot assume any global has no security concerns.

    L D


    Ok, thanks for the info!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Accessing Global Values wp_link_pages’ is closed to new replies.