MENU service case
 Website construction website design Beijing website construction high-end website production company Shangpin China
We create by embracing change
360 ° brand value__
simplified Chinese character
Simplified Chinese English

Shangpin China Joins Hands with Beisheng Internet to Create a New Chapter in Website Construction

Type: Shangpin Dynamic Learn more

How to jump to the specified page after WordPress login

Source: Shangpin China | Type: website encyclopedia | Time: January 19, 2012

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 wordpress installation file. 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';
}
Source Statement: This article is original or edited by Shangpin China's editors. If it needs to be reproduced, please indicate that it is from Shangpin China. The above contents (including pictures and words) are from the Internet. If there is any infringement, please contact us in time (010-60259772).
TAG label:

What if your website can increase the number of conversions and improve customer satisfaction?

Make an appointment with a professional consultant to communicate!

* Shangpin professional consultant will contact you as soon as possible

Disclaimer

Thank you very much for visiting our website. Please read all the terms of this statement carefully before you use this website.

1. Part of the content of this site comes from the network, and the copyright of some articles and pictures involved belongs to the original author. The reprint of this site is for everyone to learn and exchange, and should not be used for any commercial activities.

2. This website does not assume any form of loss or injury caused by users to themselves and others due to the use of these resources.

3. For issues not covered in this statement, please refer to relevant national laws and regulations. In case of conflict between this statement and national laws and regulations, the national laws and regulations shall prevail.

4. If it infringes your legitimate rights and interests, please contact us in time, and we will delete the relevant content at the first time!

Contact: 010-60259772
E-mail: [email protected]

Communicate with professional consultants now!

  • National Service Hotline

    400-700-4979

  • Beijing Service Hotline

    010-60259772

Please be assured to fill in the information protection
Online consultation

Disclaimer

Thank you very much for visiting our website. Please read all the terms of this statement carefully before you use this website.

1. Part of the content of this site comes from the network, and the copyright of some articles and pictures involved belongs to the original author. The reprint of this site is for everyone to learn and exchange, and should not be used for any commercial activities.

2. This website does not assume any form of loss or injury caused by users to themselves and others due to the use of these resources.

3. For issues not covered in this statement, please refer to relevant national laws and regulations. In case of conflict between this statement and national laws and regulations, the national laws and regulations shall prevail.

4. If it infringes your legitimate rights and interests, please contact us in time, and we will delete the relevant content at the first time!

Contact: 010-60259772
E-mail: [email protected]