I want to use Pagination throughout a new theme but am having trouble getting it to work correctly.

I am using some code within my functions.php file and then calling that function. It works on the 'blog' page but not on paginated posts or pages.

Here is my code:

// Pagination for paged posts, Page 1, Page 2, Page 3, with Next and Previous Links, No plugin
function canvas_pagination()
    global $wp_query;
    $big = 999999999;
    echo paginate_links(array(
        'base' => str_replace($big, '%#%', get_pagenum_link($big)),
        'format' => '?paged=%#%',
        'current' => max(1, get_query_var('paged')),
        'total' => $wp_query->max_num_pages,
        'type' => 'list'

add_action('init', 'canvas_pagination'); // Add our Pagination

And call the funtion: <?php get_template_part('pagination'); ?>

This code works great within the index.php file. See here: http://website-test-lab.com/sites/blank_canvas/blog/

But not within single.php and page.php:

  • SITE URL + /paginated/
  • SITE URL + /page-pagination/ (Can't add more than 2x links here)

Can someone explain why this doesn't work and what needs to be amended to fix it.

I have tried using wp_link_pages but it's not giving me the ability to customise the output I require.

Thanks in advance

2 Answers 2


Post Navigation

Here's the way its done in the Twenty Twelve themes single.php file however it looks like Twenty Fourteen has a better solution which works for pages as well.

<nav class="nav-single">
                <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3>
                <span class="nav-previous"><?php previous_post_link( '%link', '<span class="meta-nav">' . _x( '&larr;', 'Previous post link', 'twentytwelve' ) . '</span> %title' ); ?></span>
                <span class="nav-next"><?php next_post_link( '%link', '%title <span class="meta-nav">' . _x( '&rarr;', 'Next post link', 'twentytwelve' ) . '</span>' ); ?></span>
            </nav><!-- .nav-single -->

You could hook this code in from your functions file using a theme specific hook or filtering the WordPress content hook.

There's some good examples of using the content filter in your functions file here.

More http://codex.wordpress.org/Next_and_Previous_Links

Page Navigation

Here's a tutorial i wrote which uses the code from Twenty Fourteen theme.

It creates a template tag you can use in a custom function with hook and conditional tags or directly in a template file.

  • Thanks. Not quite what I was looking for but will look into the 2014 theme to see if that will help. Commented Jan 4, 2014 at 18:55
  • I think what I need is wp_link_pages, customised. Commented Jan 4, 2014 at 19:02
  • I think what you need are 2 functions. One for posts and one for archive pagination. Both of which you'll find in Twenty Fourteen or any other default theme. Commented Apr 29, 2014 at 18:37
  • Was this question ever resolved? Commented Aug 5, 2016 at 16:01

Step:1 Make Function in function.php

function vb_pagination( $query=null ) { 
  global $wp_query;
  $query = $query ? $query : $wp_query;
  $big = 999999999; 

  $paginate = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'type' => 'array',
'total' => $query->max_num_pages,
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'prev_text' => __('&laquo;'),
'next_text' => __('&raquo;'),

 if ($query->max_num_pages > 1) :
<ul class="pagination">
  foreach ( $paginate as $page ) {
    echo '<li>' . $page . '</li>';

Step : 2 call the pagination function require to use

<?php if ( function_exists('vb_pagination') ) {
                    vb_pagination( $the_query );
                } ?>
  • Please clean up your post and remove plain text from the code block. As it stands, you whole post is in one big code block Commented Mar 3, 2016 at 5:43
  • Downvoted due to your code being really messy after I have asked you to clean it up Commented Mar 3, 2016 at 14:24

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.