登录重定向到特定页面

时间:2016-05-05 03:35:12

标签: wordpress wordpress-plugin

我希望我的wordpress插件重定向到自定义页面,请参阅下面的页面。请参考下面给出的编码

登录后登录页面我希望他们移动到特定网址。

我已经尝试了几个插件,所有人都没有完成这项工作。我用过:https://wordpress.org/plugins/redirect-after-login/

所以请帮我编辑wordpress中的一些编码。

请参阅登录/注册页面模板(template-register.php)

<?php
/* Template Name: Login/Register */
get_header();
/* Site Showcase */
imic_page_banner($pageID = get_the_ID());
/* End Site Showcase */
/* Login/Register Page Design Layout
============================================*/
$pageLayout = get_post_meta(get_the_ID(),'imic_register_layout',true);
$contentClass = 4;
if ($pageLayout != 1) { $contentClass = 6; }?>
<!-- Start Content -->
<div class="main" role="main"><div id="content" class="content full"><div class="container">
<div class="page"><div class="row">
<?php
echo '<div class="col-md-'.$contentClass.' col-sm-'.$contentClass.'">';
/* Page Content
======================*/
while (have_posts()):the_post();
the_content();
endwhile;
echo '</div>';
/* Manage Login Form
========================*/
if ($pageLayout == 1 || $pageLayout == 2) { ?>
<div class="col-md-4 col-sm-4 login-form">
<h3><?php _e('Login','framework'); ?></h3>
<form id="login" action="login" method="post">
<?php
$redirect_login= get_post_meta(get_the_ID(),'imic_login_redirect_options',true);
$redirect_login=!empty($redirect_login)?$redirect_login:  home_url();
?>
<input type ="hidden" class ="redirect_login" name ="redirect_login" value ="<?php echo $redirect_login ?>"/>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input class="form-control input1" id="loginname" type="text" name="loginname">
</div>
<br>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
<input class="form-control input1" id="password" type="password" name="password">
</div>
<div class="checkbox">
<input type="checkbox" checked="checked" value="true" name="rememberme" id="rememberme" class="checkbox"> <?php _e('Remember Me!','framework'); ?>
 <?php echo '<a href="'.imic_get_template_url('template-reset_password.php').'" title="'.__('Forget Password','framework').'">'.__('Forget Password','framework').'</a>'; ?>
</div>
<input class="submit_button btn btn-primary button2" type="submit" value="<?php _e('Login Now','framework'); ?>" name="submit">
<?php wp_nonce_field( 'ajax-login-nonce', 'security' ); ?><p class="status"></p>
</form>
</div>
<?php } ?>
</div></div></div></div></div>
<?php  get_footer(); ?>

2 个答案:

答案 0 :(得分:0)

无需在WordPress中创建表单进行登录。 WordPress为此提供功能。 您可以使用wp_login_form($args)功能登录。

将此代码放入模板文件中。

$redirect_url = get_site_url();
$args = array(
            'echo' => true,
            'redirect' => $redirect_url,
            'form_id' => 'loginform',
            'label_username' => __('Email Address'),
            'label_password' => __('Password'),
            'label_remember' => __('Remember Me'),
            'label_log_in' => __('Log In'),
            'id_username' => 'user_login',
            'id_password' => 'user_pass',
            'id_remember' => 'rememberme',
            'id_submit' => 'wp-submit',
            'remember' => true,
            'value_username' => NULL,
            'value_remember' => false);
wp_login_form($args);

我希望这对你有用。

答案 1 :(得分:0)

wordpress中有一个重定向功能。请点击此链接https://codex.wordpress.org/Function_Reference/wp_redirect

在get_header()语句之前使用此函数。

希望它会有所帮助。