如何将成功的注册重定向到页面模板?

时间:2011-06-10 作者:janoChen

每次注册时,我都会进入wp登录页面(后端):

enter image description here

是否有任何方法可以将注册用户重定向到页面模板(前端)?

4 个回复
最合适的回答,由SO网友:TheDeadMedic 整理而成

您可以使用过滤器registration_redirect 例如,传回您自己的URL;

function wpse_19692_registration_redirect() {
    return home_url( \'/my-page\' );
}

add_filter( \'registration_redirect\', \'wpse_19692_registration_redirect\' );
把它放在你的functions.php 或插件:)

SO网友:user1623918

This is what i use

<form action="<?php echo site_url(\'wp-login.php?action=register\', \'login_post\') ?>" method="post">
<input type="text" name="user_login" value="Username" id="user_login" class="input" />
<input type="text" name="user_email" value="E-Mail" id="user_email" class="input"  />
<?php do_action(\'register_form\'); ?>
<input type="submit" value="Register" id="register" />
<input type="hidden" name="redirect_to" value="/success"/>
<p class="statement">A password will be e-mailed to you.</p>
</form>
SO网友:John Stones

如果你喜欢我,你可以使用ProfilePress 要启动/创建WordPress注册表,以下代码将自动登录并将注册用户重定向到欢迎页面。

add_action( \'pp_after_registration\', \'pp_redirect_after_registration\', 10, 3 );

function pp_redirect_after_registration( $form_id, $user_data, $user_id ) {

    wp_set_auth_cookie( $user_id );
    wp_set_current_user( $user_id );

    $custom_page_url = \'http://example.com/welcome/\';

    wp_redirect( $custom_page_url );
    exit;
}
注意:我使用免费插件(https://wordpress.org/support/plugin/ppress) 版本和以上代码在免费版和PRO版中都可用。

SO网友:csehasib

我已经为这个问题开发了一个插件。下面还提供了无插件重定向的原始代码。

/**
 * Redirect users to custom URL based on their role after login
 **/
function wp_woo_custom_redirect( $redirect, $user ) {

    // Get the first of all the roles assigned to the user
    $role = $user->roles[0];
    $dashboard = admin_url();
    $myaccount = get_permalink( wc_get_page_id( \'my-account\' ) );

    if( $role == \'administrator\' ) {

        //Redirect administrators to the dashboard
        $admin_redirect = get_option(\'admin_redirect\');
        $redirect = $admin_redirect;
    } elseif ( $role == \'shop-manager\' ) {

        //Redirect shop managers to the dashboard
        $shop_manager_redirect = get_option(\'shop_manager_redirect\');
        $redirect = $shop_manager_redirect;
    } elseif ( $role == \'customer\' || $role == \'subscriber\' ) {

        //Redirect customers and subscribers to the "My Account" page
        $customer_redirect = get_option(\'customer_redirect\');
        $redirect = $customer_redirect;
    } else {

        //Redirect any other role to the previous visited page or, if not available, to the home
        $redirect = wp_get_referer() ? wp_get_referer() : home_url();
    }
    return $redirect;
}
add_filter( \'woocommerce_login_redirect\', \'wp_woo_custom_redirect\', 10, 2 );
使用插件或不使用代码,您是否感到舒适?您可以下载并安装我的插件“WP WooCommerce Redirect“”

结束

相关推荐

Add new post redirection

我不知道我的网站出了什么问题,这是第二个重定向问题,每当我添加一篇新文章,在添加标题后,当我尝试添加内容时,我自己的网站主页会出现在内容框旁边的一个红色边框框中,一个页面试图加载,这个页面一直在加载,没有任何内容,加载页面的url是“http://mywebsite.com/wp-admin/post-new.php“”