I have this code in a template file that will contain my vue app that I want to load in WordPress.
<?php
/*
* Template name: App
*/
ob_start();
get_header();
if( is_user_logged_in() ) {
?>
<div id="app"></div>
<?php
} else {
wp_redirect( wp_login_url() );
exit;
}
get_footer();
ob_get_flush();
?>
I want to redirect users to the login page and this seems working fine, what I need to do is to rename the wp-login.php
page in login.php
or login
and I've tried using .htaccess rewrite rule
# BEGIN WordPress
# Le direttive (linee) tra `BEGIN WordPress` e `END WordPress` sono
# generate dinamicamente, e dovrebbero essere modificate solo tramite i filtri di WordPress.
# Ogni modifica alle direttive tra questi marcatori verrà sovrascritta.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /mysite/extranet/
# Riscrittura url di login
RewriteRule ^login$ /wp-login.php [NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /mysite/extranet/index.php [L]
</IfModule>
# END WordPress
I've noticed that this will not work as expected. Is there something else I can do to achive this?
if( ! is_user_logged_in() ) {
be simpler? It would avoid the need for output buffers. I'd also suggest usingwp_safe_redirect
since you already know that you're redirecting to a URL on the same installwp-login.php
will never work, but creating your own login page at the URL you want, then using filters to force WP andwp_login_url
to return your custom URL instead is both widespread and a question that's already been asked and answered on this stack in many forms. wordpress.stackexchange.com/search?q=custom+login+pagewp-login.php
cannot be moved or rewritten, not without forking WordPress and making major structural changes, that's why there are filters such aslogin_url
wp_login_form
is not necessary, it's just a helper function used by the login/logout widget, not the singular official method of printing a login form. Lots of people build login forms without ever touching that function