-1

Goal:

Add pagination below single post pages.

Code

function add_pagin( $content ) {
    if ( is_singular('post') ) {
        $content .= previous_post_link() . next_post_link();
    }
    return $content;
}
add_filter( 'the_content', 'add_pagin' );   

Result

Pagination added to the top of the_content, not below it. If I change $content.= to echo a simple string it works, but not with those two wprdpress functions.

I appreciate the help with this.

5

previous_post_link and next_post_link both output the link directly, which won't work in your case because you're trying to assign the result to a variable. Use get_previous_post_link() and get_next_post_link() instead-

function add_pagin( $content ) {
    if ( is_singular('post') ) {
        $content .= get_previous_post_link() . get_next_post_link();
    }
    return $content;
}
add_filter( 'the_content', 'add_pagin' );   

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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