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' );