• Resolved 818903

    I’m using wordpress 2.6 to manage a website for a novel I’ve written. I have it set up so that the main site is a static page instead of the default chronological list of posts.

    I want to set up the site so that users are redirected to the main page after they log in. I don’t want them going to the dashboard or writing screen or profile screen. They should go straight to the site’s home page.

    Unfortunately, I don’t write code as well as I write books! I searched the forums before I posted this question, and I found this:

    <?php
    /*
    Plugin Name: Redirect user to front page
    Plugin URI: https://www.theblog.ca/wplogin-front-page
    Description: When a user logs in via wp-login directly, redirect them to the front page.
    Author: Peter
    Version: 1.0
    Author URI: https://www.theblog.ca
    */
    
    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');
    ?>

    It sounded like it was what I needed, but I couldn’t get it to work. I put my site url in the right place, but i got a blank screen when I activated it and tried it.

    Does anyone have any suggestions ?

Viewing 8 replies - 16 through 23 (of 23 total)
  • Maybe try upgrading to 2.6?

    Although this works for me in terms of the admin url change to siteurl, there is no differentiator between an Admin and a subscriber, it takes me to the home page regardless. I need the admin to goto the Admin and a Subscriber goto Home. Or is what I am asking handled by a Plugin? Preferred Plugin that has been used out there?

    Here’s what you can do in wp-login.php (2.5)

    Change line 392 to the following:

    <input type="hidden" name="redirect_to" value="<?php echo get_bloginfo('home'); ?>" />

    I had the same issue as tommy2guns from the beginning (2.5).

    What worked for me was to modify wp-login.php in case ‘logout’ :
    `
    wp_logout();

    //—add this—
    $redirect_to = get_bloginfo(‘home’);

    wp_safe_redirect($redirect_to);
    exit();

    Can the wp-register requirement be created so that it only applies to posts and pages, but not to the home page? I’d like people to be able to reach the home page so they can see the posts, etc. before they are required to register when they click on a post,page, etc.

    This is so ridiculous (frustration level growing… ;o)

    In wp-login.php:

    – find where it says:

    case ‘login’ :
    default:
    if ( isset( $_REQUEST[‘redirect_to’] ) )
    $redirect_to = $_REQUEST[‘redirect_to’];
    else
    $redirect_to = admin_url();

    – Change:

    $redirect_to = admin_url();

    to:

    $redirect_to = site_url();

    ——–

    Before you do this, ensure your theme provides a link on your home page to login/logout and register/site admin.

    Is it possible to accomplish this in the functions.php file so that it will survive an upgrade?

    Good question, afge1106. Since the last post was a month ago and the question marked as Resolved. You may get better response if you start a new thread and direct an explanation to this thread.

Viewing 8 replies - 16 through 23 (of 23 total)
  • The topic ‘redirect after user login’ is closed to new replies.