我尝试了wordpress堆栈,但没有成功,所以我想在这里尝试。。。
因此,我试图在我的一个页面上显示默认wordpress登录表单的工作版本。functions.php文件中有创建短代码的代码,据我所知,它工作成功,但在提交表单后,它只是刷新页面,不会重定向到我指定的url。。。有人能理解为什么它可能不能正常工作吗?
这是我放在functions.php文件中的函数:
//Login form Shortcode
add_shortcode( 'login-form', 'my_login_form_shortcode' );
/**
* Displays a login form.
*
* @since 0.1.0
* @uses wp_login_form() Displays the login form.
*/
function my_login_form_shortcode( $atts, $content = null ) {
$defaults = array( "redirect" => site_url( $_SERVER['REQUEST_URI'] )
);
extract(shortcode_atts($defaults, $atts));
if (!is_user_logged_in()) {
$content = wp_login_form( array( 'echo' => false, 'redirect' => $redirect ) );
}
return $content;
}
然后我把它放在想要的页面上,如下所示:
[login-form redirect="https://myurl.com"]
但它并没有将我重定向到正确的页面,而是刷新页面,即使我现在已经成功登录了…有什么想法吗?
您可以简单地在下面添加此代码
add_action( 'login_form_middle', 'add_lost_password_link' );
function add_lost_password_link() {
return '<a href="/wp-login.php?action=lostpassword">Forgot Your Password?</a>';
}
if(!function_exists('vivid_login_page'))
{
function vivid_login_page()
{
$args = array(
'echo' => true,
'remember' => true,
'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
'form_id' => 'loginform',
'id_username' => 'user_login',
'id_password' => 'user_pass',
'id_remember' => 'rememberme',
'id_submit' => 'wp-submit',
'label_username' => __( 'Username or Email Address' ),
'label_password' => __( 'Password' ),
'label_remember' => __( 'Remember Me' ),
'label_log_in' => __( 'Log In' ),
'value_username' => '',
'value_remember' => false
);
wp_login_form($args);
add_lost_password_link();
}
add_shortcode('vivid-login-page', 'vivid_login_page');
}