Update (Jan 7th): I realize this plugin is basically unnecessary although it might have some use in some applications. What you can do instead is just use a link, with a redirect parameter.
<a href=”http://yourwordpresssite.com/wp-login.php?redirect_to=http%3A%2F%2Fyourwordpresssite.com%2Fyourpage%2F&reauth=1″>Please Log In</a>
—Original Post Below—
I wrote a simple plugin which presents a login link which will redirect the user, after logging in, to your site’s home page or to a URL of your choice. WordPress’s default behavior is to bring users to the admin panel.
With this plugin, you can put the following shortcode in a page or post:
[loghome]
,
or with the url and/or text options like this:
[loghome url="http://yoursite.com/alternatepage.php" text="Sign In Here"]
.
It will turn into a link with the text “Log in”, or what you put in the text field, and will redirect to your home page or what you put in the url field.
Since it’s a plugin, put the code in a file, like logtohome.php, and put that file in your plugins directory, or in a new subdirectory. For example: /yourserver/www/wp-content/plugins/logToHome/logtohome.php.
Then activate the plugin.
Alternatively, If you don’t want to use it as a plugin, you can put the function in your theme’s functions.php file. The advantage of a plugin is it doesn’t go away when you change themes.
<?php /*Plugin Name: Log to Home Plugin URI: http://bnmng.com/ Description: Displays the contents of a selected page. Author: Benjamin Goldberg Version: 1 Author URI: http://bnmng.com/ */ function logtohome( $atts ){ $defaulturl= home_url() ; $defaulttext='Log in'; extract( shortcode_atts( array( 'url' => $defaulturl, 'text' => $defaulttext ), $atts ) ); $loginurl='<a href="' . wp_login_url( $url ) . '" title="Login">' . $text . '</a>'; return $loginurl; } add_shortcode( 'loghome', 'logtohome' ); ?>
The reason this is so simple is WordPress already has a function which does all the work, wp_login_url( $url )
. For the most part, this plugin is just a wrapper for that function.