Reputation: 703
In my project, I'm using wordpress as a headless cms for just the wp rest apis and with a blank theme ( just the index.php and style.css). I want the user to redirect to the wordpress dashboard when he visits the homepage in frontend. I tried putting the redirect in the index.php in the root directory in wordpres like this
header("Location: /wp-admin");
define( 'WP_USE_THEMES', true );
/** Loads the WordPress Environment and Template */
require __DIR__ . '/wp-blog-header.php';
But its not working and I'm not sure if its right too. How can I do this?
Upvotes: 0
Views: 183
Reputation: 338
Well you can try on your functions.php something like this:
<?php
function redirect_wpadmin(){
$url2go = get_bloginfo('url').'/wp-admin';
if (is_home()) {
wp_redirect($url2go);
exit;
}
}
add_action('init','redirect_wpadmin');
This should do the work c:
--Update--
I also think that you can do this with htaccess, adding inside and at the bottom of <IfModule mod_rewrite.c>
:
Redirect 301 / /wp-admin
Upvotes: 0
Reputation: 703
I fixed it by simply adding this in the index.php file inside the theme
header("Location: ".admin_url());
exit;
Upvotes: 1