Thanks for Stopping By!
You clicked the link because it was blue and shiny didn’t you?
Oh well. I’m Big Bagel. I host webcomics, make WordPress plugins, and spend the rest of my time being awesome. Here’s my profile on WordPress.org.
If you’re interested in what’s here, you should check out the home page.
3 Comments
Thanks for helping me out with my tag-based post list thingy on the WordPress forum – I’m eternally grateful! Interesting site here, I wasn’t familiar with the Webcomic plugin. I actually long to spend my days cartooning rather than coding – coding doesn’t come at all naturally to me!
cheers,
Steve (stevoweb)
I need help and seen a stackflow post which suggests your the man! I need a simple code that redirects users from the home page to another page ID ONLY if LOGGED IN.
Could you help me?
Matthew
Which Stack Overflow question? I’m curious since I’ve never even posted there.
The three things you’re most likely looking for are
is_front_page()to determine if your front page is being displayed,is_user_logged_in()to determine if the user is logged in (obviously), andwp_redirect()to redirect the page.is_front_page()
is_user_logged_in()
wp_redirect()
The only thing you really need to know beyond that is that
is_front_page()will only work after init, andwp_redirect()will only word before template_redirect, so you’ll want to hook into something in between, like wp_loaded. Hooking init with a priority above 10 would probably work as well, but I can’t be sure without testing.Something like the following should work (it’s completely untested though):
add_action( 'wp_loaded', 'redirect_front_page' );
function redirect_front_page() {
if ( is_front_page() && is_user_logged_in() ) {
wp_redirect( 'http://example.com/example-page' );
die();
}
}
wp_redirect()takes an absolute URL so if you want to use the id of the page you can use a URL like: “http://example.com/?p=1″ with the number obviously being your post id. If you want to further filter this by user role you can also usecurrent_user_can()instead ofis_user_logged_in().current_user_can()