Last updated on September 25th, 2021 at 08:31 pm
When using the WordPress pagination feature, with some themes it can end up being out of the way and your visitors might not see it. This can cause issues where you visitor will get frustrated and leave your website. This also then starts to push up your bounce rate.
I had this problem so I wanted my pagination buttons to be directly underneath my post, so that it was clear to my visitors how to get to the next page.
Plugin v Code
There are a number of plugins you can use to do this but I already use far too many plugins as it is, so I wanted to code it into my theme.
I started Googling how to do this and I came across a post on Stack Exchange which offered a solution. I tested it out and it worked a treat.
Below is the code that allows you to have your pagination buttons just below your post. This should be copy and pasted into your functions.php file – I suggest adding this to your child theme so that it does not disappear on the next theme update.
Pagination Buttons Code
<?php // move pagination links above other end-of-post content additions, like related posts etc.
function move_pagination( $content ) {
if ( is_single() ) {
$pagination = wp_link_pages( array(
'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'firmness' ) . '</span>',
'after' => '</div>',
'link_before' => '<span>',
'link_after' => '</span>',
'echo' => 0,
) );
$content .= $pagination;
return $content;
}
return $content;
}
add_filter( 'the_content', 'move_pagination', 1 );
Bad Syntax
Please be very aware – if you do copy and paste this code above, check the syntax as the formatting can get a little messed up, always check speech marks as this is normally what get screwed up on copy and pasting from the internet.
Feedback
If you have any questions or comments on this post, please feel free to either leave a comment below or use one of our many social media platforms.
Newsletter
If you want to be notified when we post more quality guides like this one, sign up to our newsletter and you will receive an email when a new post is live.
Don’t worry, we won’t be filling your inbox with spam and you can unsubscribe anytime you like.