I believe this is completely different than the question asked here.

I'm adding pagination to my theme using a filter hook. The output appears at the beginning and end of my content, rather than just the end.

My function, in the template's functions.php file:

 * Adds pagination after the post
 * @uses is_single()

function pagination_after_post($content){
    if( is_single() ){
        $content .= '<div class="pagination">' . wp_link_pages('before=&after=&next_or_number=next&nextpagelink=Next&previouspagelink=Previous') . '</div>';
        return $content;
    } // if
} // pagination_after_post

Here is my single.php:

<?php get_header(); ?>

        <div id="centercol">

        <?php if (have_posts()) : ?>

            <?php while (have_posts()) : the_post(); ?>

                <div class="post" id="post-<?php the_ID(); ?>">

                    <h2 class="singleh2"><a title="<?php _e('Permanent Link to',woothemes); ?> <?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
                    <div class="date-comments">
                        <p class="fl"><?php the_time('l, M j, Y \a\t g:i a'); ?> by <a href="<?= get_author_posts_url( get_the_author_meta( 'ID' ) ) ?>" rel="author"><?= get_the_author() ?></a></p>
                        <p class="fr"><?php the_category(', ') ?></p>                                                 

                    <div class="entry">
                        <?php echo woo_get_embed('embed','500','360','video-post'); ?>
                        <?php the_content(__('<span class="continue">Continue Reading</span>',woothemes)); ?>                       

                    <?php the_tags('<p>Tags: ', ', ', '</p>'); ?> 


                <div id="comments">
                    <?php comments_template(); ?>

        <?php endwhile; ?>

        <div class="navigation">
            <div class="alignleft"><?php previous_post_link(); ?></div>
            <div class="alignright"><?php next_post_link(); ?> </div>

    <?php endif; ?>                         


<?php get_sidebar(); ?>

<?php get_footer(); ?>

And a screenshot of the issue:

enter image description here

  • in your functions.php did you added action hook? Commented Sep 14, 2011 at 18:15
  • oops you need to add add_filter Commented Sep 14, 2011 at 18:16
  • @ntechi I've got add_filter('the_content','pagination_after_post',1); on the first line. Anything more than that? Commented Sep 14, 2011 at 18:17
  • check my answer Commented Sep 14, 2011 at 18:20

2 Answers 2


you need to set the 'echo' parameter of wp_link_pages() to 'echo=0'; example:

$content .= '<div class="pagination">' . wp_link_pages('before=&after=&next_or_number=next&nextpagelink=Next&previouspagelink=Previous&echo=0') . '</div>';

You need to do something like this

add_filter ('the_content', 'pagination_after_post',1);
function pagination_after_post($content) {
   if(is_single()) {
      $content.= '<div class="pagination">' . wp_link_pages('before=&after=&next_or_number=next&nextpagelink=Next&previouspagelink=Previous') . '</div>';

   return $content;
  • How is this different from what I posted, besides the lack of a comment between the add_filter and the function? Commented Sep 14, 2011 at 18:24
  • Oh, the return is outside the if. Trying now. Commented Sep 14, 2011 at 18:26
  • Moved the return outside the if single. The issue persists. It's not that I have 0 returned results, it's that I have two, one before and one after the content. It feels like it's doing "pagination" . $content . "pagination". Commented Sep 14, 2011 at 18:29

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.