• With the default wp_link_pages the current/active page number is not a link. I would like to find a code/hack which turns the current/active page into a link to the top of the page. I am trying to create a similar look/functionality to the post navigation fond at the bottom of this page.

    I am already using a custom code for wp_link_pages which can be found below:

    <?php
    wp_link_pages(array(
        'before' => '<p class="pagelinks">' . __(''),
        'after' => '</p>',
        'next_or_number' => 'next_and_number', # activate parameter overloading
        'nextpagelink' => __('Next'),
        'previouspagelink' => __('Previous'),
        'pagelink' => '%',
        'echo' => 1 )
    );
    ?>

    And in my functions:

    // Custom Next/Previous Page
    add_filter('wp_link_pages_args', 'wp_link_pages_args_prevnext_add');
    /**
     * Add prev and next links to a numbered link list
     */
    function wp_link_pages_args_prevnext_add($args)
    {
        global $page, $numpages, $more, $pagenow;
    
        if (!$args['next_or_number'] == 'next_and_number')
            return $args; # exit early
    
        $args['next_or_number'] = 'number'; # keep numbering for the main part
        if (!$more)
            return $args; # exit early
    
        if($page-1) # there is a previous page
            $args['before'] .= _wp_link_page($page-1)
                . $args['link_before']. $args['previouspagelink'] . $args['link_after'] . '</a>'
            ;
    
        if ($page<$numpages) # there is a next page
            $args['after'] = _wp_link_page($page+1)
                . $args['link_before'] . $args['nextpagelink'] . $args['link_after'] . '</a>'
                . $args['after']
            ;
    
        return $args;
    }

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘wp_link_pages: Link current/active page to top of page’ is closed to new replies.