Hello.
If you take a look at the login link from “Episode 228”:
https://secularbuddhism.org/frontdoor?redirect_to=http%3A%2F%2Fsecularbuddhism.org%2F2015%2F08%2F02%2Fepisode-228-bj-leiderman-npr-music-meditation-and-moving-from-sound-to-silence%2F
There is a redirect_to
parameter containing the current post’s URL. This is the part missing in your forum page.
Now, how to make properly a link to the login page:
First, there is a function for that, wp_login_url().
To use it, we must catch the current page’s URL.
We could try to get the permalink on the current page with get_permalink( get_queried_object_id() )
but the forum adds a bunch of other parameters (mingleforumaction, f, t, id…) so we must know them all to add them one by one. Not an easy task.
Instead, we’ll use a function I created that returns the current page’s URL:
if ( ! function_exists( 'sf_get_current_url' ) ) :
function sf_get_current_url( $mode = 'base' ) {
$mode = (string) $mode;
$url = ! empty( $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI'] ) ? $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI'] : ( ! empty( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '' );
$url = 'http' . ( is_ssl() ? 's' : '' ) . '://' . $_SERVER['HTTP_HOST'] . $url;
switch( $mode ) :
case 'raw' :
return $url;
case 'uri' :
$url = reset( ( explode( '?', $url ) ) );
$url = reset( ( explode( '&', $url ) ) );
return trim( str_replace( home_url(), '', $url ), '/' );
default :
$url = reset( ( explode( '?', $url ) ) );
return reset( ( explode( '&', $url ) ) );
endswitch;
}
endif;
And then, create the login URL is easy:
echo '<a href="' . esc_url( wp_login_url( sf_get_current_url( 'raw' ) ) ) . '">' . __( 'Log In' ) . '</a>';
For the registration URL there is also a function: wp_registration_url(), but it doesn’t need any parameter.
echo '<a href="' . esc_url( wp_registration_url() ) . '">' . __( 'Register' ) . '</a>';
I hope it will solve your problem.
PS: don’t forget esc_url()
around the URL, it’s an important security part.