Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have installed a site in my localhost. I have used a static home page with a wordpress login in it. The blog is hosted at localhost/blog.

(i have followed the wordpress guide on how to get the wordpress index by keeping it inside a sub folder)

the issue im having is once the user is logged in it automatically redirects to the /blog path. But i want to redirect it to the main home page.

This is what i have tried so far

Added the below code to the functions.php

/* redirect users to front page after login */    
function redirect_to_front_page() {
    global $redirect_to;
    if (!isset($_GET['redirect_to'])) {
        $redirect_to = get_option('siteurl');
    }
}
add_action('login_form', 'redirect_to_front_page'); 

added plenty of login redirect modules but none of them work, all of those simply redirects to the blog page.

share|improve this question
    
First, there're plenty of exactly those questions. Second you're missing the exit;. –  kaiser Aug 26 '13 at 16:20
    
possible duplicate of How to redirect/rewrite all /wp-login requests –  kaiser Aug 26 '13 at 16:21
    
@kaiser tried all the examples including the exit;... it doest redirect to the home. PLEASE read the question before you down vote. what i need is to redirect to the homepage after the user logs in to the site and your answer is about rewriting the URLs for logins, which is totally irrelevant! –  LiveEn Aug 26 '13 at 16:45
    
I read your question, but marked the wrong one from the selection. Later voters might choose the right one. Just search for "redirect" on the site. Your actual problem has been solved a hundred times. Check if the user is logged in, redirect, exit ... and use the right hook. The down vote btw wasn't for it being a duplicate, but for not caring about intending the code above > hard to read. –  kaiser Aug 26 '13 at 17:18
    
Can you tell me your static home page url? –  Vinod Dalvi Aug 26 '13 at 17:50

1 Answer 1

You can use the wp-login.php?redirect_to option and build your URL like this:

$url = home_url();
echo "<a href=\"" . $url . "/wp-login.php?redirect_to=" . $url . "\">Click Here</a> to login";

I'm not sure where you are trying to do this so it may not suit your requirement but if you give more info I may be able to help.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.