0

While using paginate_links() function of WordPress, i need to change the order in which it echo's its output. For example, by default it will output pagination links in this format:

Default Output:

<<PREV 1 2 3  NEXT>>

But i need its output in following format:

Required Output:

1 2 3 <<PREV NEXT>>

Now, the question is, how to change the order of these pagination links as per my requirement?

1 Answer 1

1

You cannot do this with the default paginate_links() functions. Looking at the source code, there are no filters from which you can change the layout as you wish

ALTERNATIVE SOLUTIONS

Although you cannot do this by default, it doesn't mean that you cannot get your desired output. Here is a couple of options to explore

OPTION 1

Write a wrapper function for paginate_links() and set prev_next to false

You can then use get_next_post_link() and get_previous_post_link() to display the next and previous post link text ( <<PREV NEXT>>)

Try something line this: (CAVEAT: Untested, might be buggy)

function my_paginate_links() {

    $args = array( //Add arguments as needed
        'prev_next'    => false,
    );

    $number_link = paginate_links( $args );

    $previous = get_previous_posts_link( '<<PREV ' );
    $next = get_next_posts_link( ' NEXT>>' );

    $link = $number_link . $previous . $next;

    return $link;

}

In your template file, just use it as

echo my_paginate_links();

OPTION 2

If option 1 fails, you can copy the paginate_links() function to your theme, rename it, and modify the source code as needed to get the desired output

OPTION 3

Write your own function to get the desired output. For a little inspiration, check out this custom function I have recently done in another answer on this site. Use and abuse it as you see fit.

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.