Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8609707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:56:41+00:00 2026-06-12T03:56:41+00:00

I have some very long posts, some have more than 50 pages() and when

  • 0

I have some very long posts, some have more than 50 pages() and when using wp_link_pages it give me 50 internal post links, clearly this isn’t usable.

I need to add a range to the wp_link_pages function, because as it stands now we output 50 paginated links.

The output should look like this: …45*6*78…

I’ve got the logic for adding the range but now I need to figure out how to add it to the existing wp_link_pages function?

Here is the example function:

function limitPagination(){
    $displayPages = 5;
    $firstPage = 1;
    $lastPage = $numpages > 5;

    while($numpages > $displayPages){
        if(($pageNow > $firstPage +2) && ($pageNow < $lastPage - 2)){
            echo (($pageNow - 2).($pageNow - 1).$pageNow.($pageNow + 1).($pageNow + 2));
        }
    }
}

This is the function I need to add my example function to:

// Add prev and next links to a numbered link list

function custom_wp_link_pages( $args = '' ) {
    $defaults = array(
        'before' => '<p id="post-pagination">' . __( 'Pages:' ), 
        'after' => '</p>',
        'text_before' => '',
        'text_after' => '',
        'next_or_number' => 'number', 
        'nextpagelink' => __( 'Next page' ),
        'previouspagelink' => __( 'Previous page' ),
        'pagelink' => '%',
        'echo' => 1
       );

    $r = wp_parse_args( $args, $defaults );
    $r = apply_filters( 'wp_link_pages_args', $r );
    extract( $r, EXTR_SKIP );

    global $page, $numpages, $multipage, $more, $pagenow;

    $output = '';
    if ( $multipage ) {
        if ( 'number' == $next_or_number ) {
            $output .= $before;
            for ( $i = 1; $i < ( $numpages + 1 ); $i = $i + 1 ) {
                $j = str_replace( '%', $i, $pagelink );
                $output .= ' ';
                if ( $i != $page || ( ( ! $more ) && ( $page == 1 ) ) )
                    $output .= _wp_link_page( $i );
                else
                    $output .= '<span class="current-post-page">';

                $output .= $text_before . $j . $text_after;
                if ( $i != $page || ( ( ! $more ) && ( $page == 1 ) ) )
                    $output .= '</a>';
                else
                    $output .= '</span>';
                }
        $output .= $after;
            } else {
                if ( $more ) {
                    $output .= $before;
                    $i = $page - 1;
                    if ( $i && $more ) {
                        $output .= _wp_link_page( $i );
                        $output .= $text_before . $previouspagelink . $text_after . '</a>';
                        }
                        $i = $page + 1;
                        if ( $i <= $numpages && $more ) {
                           $output .= _wp_link_page( $i );
                           $output .= $text_before . $nextpagelink . $text_after . '</a>';
                        }
                        $output .= $after;
                    }
                }
            }
        if ( $echo )
        echo $output;
        return $output;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:56:43+00:00Added an answer on June 12, 2026 at 3:56 am

    The hook in your target function is this:

    $r = apply_filters( 'wp_link_pages_args', $r );
    

    That means to run your limitPagination function you hook into wp_link_pages_args. It also means that your limitPagination function must accept $r as an argument and return a modified $r rather than echoing the output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in specman: var x := some.very.long.path.to.a.variable.in.another.struct; while (x ==
I have some very simple XML: <properties> <property> <name>BobFish</name> <explaination>Bob is a fish.</explaination> </property>
I have some very basic semaphore code that works great on Linux, but cannot
I have some VERY simple code to return the title for a section header:
I have some very ugly data I am trying to massage. It consist of
I have some very basic SignalR code running on the js client: var conn
I have a page with some very basic examples that use HTML/CSS/JavaScript. I'd like
I'm very new to C# so please have some extra patience. What I am
Hi I have some experience with programming but I'm not very good with pointers.
I have a 3yr old application that has some controllers with some very unrestful

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.