简体   繁体   English

如何更改按钮的默认 Wordpress 登录页面链接?

[英]How can I change the default Wordpress Login Page link for a button?

I am using the OceanWP theme with the WP Job Manager plugin to build my job listing website.我正在使用带有 WP Job Manager 插件的 OceanWP 主题来构建我的工作列表网站。

When a user tries to 'Post a Job' when they are not logged in the WP Job Manager plugin shows a default login button which directs them to the default wp-login.php page: http://prntscr.com/pr86qn当用户在未登录时尝试“发布工作”时,WP Job Manager 插件会显示一个默认登录按钮,该按钮会将他们定向到默认 wp-login.php 页面: http://prntscr.com/pr86qn

But I wanted the user to be diverted to a new custom login/registration page I created as it does not have the 'Wordpress' logo on it and also allows users to register if they do not have an account.但是我希望用户被转移到我创建的新的自定义登录/注册页面,因为它没有“Wordpress”徽标,并且还允许用户在没有帐户的情况下进行注册。

When I clicked the "inspect element" option on this "sign in" button, I can see the link here: http://prntscr.com/pr8951当我单击此“登录”按钮上的“检查元素”选项时,我可以在此处看到链接: http://prntscr.com/pr8951

So I would like to change the link:所以我想更改链接:

<a class="button" href="https://www.XXXXXXXXXX.co.uk/wp-login.php?redirect_to=https%3A%2F%2Fwww.XXXXXXXXXX.co.uk%2Fpost-a-job%2F">Sign in</a>

(I have XX'd out my website name as I would prefer it not to show in any google search results) (我已经 XX 删除了我的网站名称,因为我不希望它出现在任何谷歌搜索结果中)

...so that it will direct the user to my new custom login/registration page instead. ...以便它将用户引导到我的新自定义登录/注册页面。

Could anyone advise which file I could change this link from or if there is a better way of changing this link?谁能建议我可以从哪个文件更改此链接,或者是否有更好的方法来更改此链接?

Thanks谢谢

This snippet will redirect all login links to the specified page (just replace /login-page/ on line 3 with the slug of your custom login page):此代码段会将所有登录链接重定向到指定页面(只需将第 3 行的 /login-page/ 替换为您的自定义登录页面的 slug):

add_filter( 'login_url', 'my_login_page', 10, 2 );
function my_login_page( $login_url, $redirect ) {
    return home_url( '/login-page/?redirect_to=' . $redirect );
}

Fix redirect issue修复重定向问题

/** Log in redirect to previous page by logicdigger **/
// start global session for saving the referer url
function start_session() {
    if(!session_id()) {
        session_start();
    }
}
add_action('init', 'start_session', 1);

// get the referer url and save it to the session
function redirect_url() {
    if (! is_user_logged_in()) {
        $_SESSION['referer_url'] = wp_get_referer();
    } else {
        session_destroy();
    }
}
add_action( 'template_redirect', 'redirect_url' );

//login redirect to referer url
function login_redirect() {
    if (isset($_SESSION['referer_url'])) {
        wp_redirect($_SESSION['referer_url']);
    } else {
        wp_redirect(home_url());
    }
}
add_filter('woocommerce_login_redirect', 'login_redirect', 1100, 2);

Try LoginPress Plugin to customize default login Page https://wordpress.org/plugins/loginpress/尝试使用 LoginPress 插件自定义默认登录页面https://wordpress.org/plugins/loginpress/

I think you need a more advanced function originally mentioned here我认为您需要更高级的 function 最初提到这里

Add this to your function file.将此添加到您的 function 文件中。

function possibly_redirect(){
  global $pagenow;
  if( 'wp-login.php' == $pagenow ) {
    if ( isset( $_POST['wp-submit'] ) ||   // in case of LOGIN
      ( isset($_GET['action']) && $_GET['action']=='logout') ||   // in case of LOGOUT
      ( isset($_GET['checkemail']) && $_GET['checkemail']=='confirm') ||   // in case of LOST PASSWORD
      ( isset($_GET['checkemail']) && $_GET['checkemail']=='registered') ) return;    // in case of REGISTER
    else wp_redirect( home_url() ); // or wp_redirect(home_url('/login'));
    exit();
  }
}
add_action('init','possibly_redirect');

Please go through FTP请从 go 到 FTP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM