• 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 15 replies - 1 through 15 (of 23 total)
  • For info (in case it wasn’t obvious,sorry ) this is the site that provided the plugin.

    If you wanted to redirect to the front page of your site, you won’t actually need to change anything. Just activate the plugin and go.

    This is because it is redirecting to the value of ‘siteurl’ in your wp_options table, which is otherwise your actual site url, or https://www.yoursite.com.

    Hope this helps.

    p/s: This looks like a potentially promising plugin as well, but not sure if it works in 2.6; From Where you Came

    Thread Starter 818903

    First, thanks for supplying the link to the author’s site. I thought I included it before the code, but I must have screwed up the tags.

    (obviously, I’m not a coder.)

    Secondly, thanks for the explanation. I feel kinda dumb for not seeing that ‘siteurl’ was a variable, but my embarrassment is eased somewhat because it does work like a charm not that I’ve quit trying to make things more complicated than they have to be.

    @tommy2guns: Yup, you did supply the link. I just thought it would be useful for others when/if they reference this thread (when they search the forums too :P) to have an extra link to visit.

    Actually, I find the question very helpful, so thank you as well. It took me a while to work out how to modify the url to a custom page on the site, so that is what I learnt from it ??

    Even though you solved your problem, I still feel I have to inform people about a much more…how do I put this…a much more no-need-for-plugin-ish way to do this (excuse that ridiculos word :D).
    Heres all you need to do (or at least this worked for me):
    Open your wordpress/wp-login.php file, and find this line:
    $redirect_to = admin_url();

    and replace it with this:

    $redirect_to = get_option('siteurl');

    There you go. A plugin might be much more comfortable to use and it might be a more convenient and easy and straightforward solution, but hey, use this if your plugin causes any kind of conflict or if you like to code yourself :D.

    Thanks jacf182 ?? This is useful information!

    How do I get the username variable they used to login with? I’d like to make an IF statement so if the username equals something, it forwards them to the dashboard, anything else will redirect them to the homepage.

    how do I redirect to a custom page (not the home page and not the admin page, another page that may even be outside of the WP environment)

    change:
    $redirect_to = get_option(‘siteurl’);

    to:
    $redirect_to = ‘https://www.newsite.com&#8217;;

    that does not worrk Berryrag, it still redirects me to the admin page, I have even tried changing it in wp-login to redirect to another page and nothing happens. I need this fixed asap please help me

    here is my tester code…..

    <?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.php 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 = 'https://www.google.com';
    	}
    }
    
    add_action('login_form', 'redirect_to_front_page');
    ?>

    and when I login via wp-login it sends me to admin, whats wrong?

    Did you try disabling the plugin, and opening the wordpress/wp-login.php

    Find the line: “$redirect_to = admin_url();”

    and replace it with this: “$redirect_to = ‘https://www.google.com&#8217;;”

    no luck it still takes me to the dashboard

    and mine says $redirect_to = ‘wp-admin/’; not admin_url();

    any ideas?

    What version of WordPress are you using?

    2.5.1

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