Web Design
Mobile Internet
Brand Design
Innovative
News
Encyclopedias

How to jump to the specified page after WordPress login

Date:2013-01-19 Source: Shangpin China Type: website encyclopedia
Word Size: small   medium   big

How to jump to the specified page after WordPress login

When writing the template, Beijing website construction 's friend asked the website to jump to the specified page after login. I've never met this before. So I used omnipotent search (rarely Baidu) to find it. The method is basically one, and the code is as follows:

<? php
// Fields for redirect function custom_login_fields() {
?>
<p><label><strong>Choose your location: </strong>
<select name="login_location">
<option value="">Select &hellip;</ option>
<option value="<?php bloginfo('url'); ?>#banking">Banking</option>
<option value="<?php bloginfo('url'); ?>#insurance">Insurance</option>
<option value="<?php echo get_permalink(2); ?>">Securities</option>
</select> </label>
</p><br/>
<? php
} // Redirect function
function location_redirect() {
$location = $_POST['login_location'];
wp_safe_redirect($location);
exit(); } // Add fields to the login form
add_action('login_form','custom_login_fields'); // Make sure the redirect happens only if your fields are submitted
if ( (isset($_GET['action']) && $_GET['action'] != ' logout') || (isset($_POST['login_location']) && ! empty($_POST['login_location'])) )
add_filter('login_redirect', 'location_redirect', 10, 3);
?>
But I tried unsuccessfully. I don't know why. So I searched again and returned to the page before login( Beijing website production ), there are the following methods:

Method 1:

There is a function named "wp_login_url()" in the installation file of wordpress. This function is used to jump to the user specified page after login Seo website optimization It can receive a parameter whose value is the URL address that can be accessed.

By using "get_permalink()" as the input parameter (the get_permalink() function is used to obtain the current page address), the page can automatically jump to the pre login page after login.

The codes are as follows:

<a title="Login" href="<?php echo wp_login_url(get_permalink()); ?>">Login to view</a>
Just copy the above code and put it on the page that the user needs to return after logging in (that is, the page before logging in).

Method 2:

function back_curPageURL() {
$pageURL = 'http';
if ( isset( $_SERVER["HTTPS"] ) AND $_SERVER["HTTPS"] == "on" )
$pageURL .= "s";
$pageURL .= "://";
if ( isset( $_SERVER["SERVER_PORT"] ) AND $_SERVER["SERVER_PORT"] != "80" )
$pageURL .= $_ SERVER["SERVER_NAME"]. ":".$_ SERVER["SERVER_PORT"].$_ SERVER["REQUEST_URI"];
else
$pageURL .= $_ SERVER["SERVER_NAME"].$_ SERVER["REQUEST_URI"];
return $pageURL;
}
add_filter('login_redirect', ' back_curPageURL ');
Add the above code to the function.php file.

I think this method is similar to the previous one.

So I changed it and it became a way to jump to the designated page after login. This is also a friend's reply to my content in the forum. The code is as follows:

add_filter('login_redirect', 'new_login_redirect');
function new_login_redirect()
{
Return 'The URL to jump to after successful login';
}


Please contact our consultant

+86 10-60259772

Please provide your contact number. The project manager of shangpin China will contact you as soon as possible.