Put condition inside your function:
add_action('before_footer','post_prev_nex');
function post_prev_nex() {
if (is_singular())
the_post_navigation();
}
In your version is_singular()
is executed when functions.php
file is loaded, not while displaying the page.