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 your visitors 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 came across a post on Stack Exchange offering 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 copied 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 usually is what gets 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.

Credithttps://wordpress.stackexchange.com/questions/168498/how-to-add-pagination-in-between-post-and-comments?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

Click to rate this post!
[Total: 1 Average: 5]

Discover more from TechyGeeksHome

Subscribe to get the latest posts sent to your email.

Avatar of Andrew Armstrong

By Andrew Armstrong

Founder of TechyGeeksHome and Head Editor for over 15 years! IT expert in multiple areas for over 26 years. Sharing experience and knowledge whenever possible! Making IT Happen.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.