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 currently have a button like this, that takes a user to their 'mentions' page

<a href="http://my.url.org/mentions/<?php global $userdata;
get_currentuserinfo(); echo( $userdata->user_login );?>">button</a>

What I'd like instead is that a user can see their 'mentions' when they log in to the page. so I'd like admin to be redirected to http://my.url.org/mentions/admin when he goes to a particular page (i.e. the homepage) - I think this would be best using a PHP redirect?

How could I do this?

share|improve this question
    
How is the "mentions" page output? Can you post the code for that page? Is this related to the P2 theme? If so, posting on their forums might give you insight as well. –  guiniveretoo Jan 5 '13 at 23:58
    
Yeah it was related to the p2 theme, however @pogoking has managed to solve the issue, thank you though –  ameeromar Jan 7 '13 at 16:10
add comment

1 Answer 1

up vote 2 down vote accepted

You have to add action to, for example, template_redirect action hook. The action would perform your desired checks and redirect user using the wp_redirect() function. The code could look something like this:

function my_redirect_function() {
    // Check if home page is being displayed
    if ( is_home() ) {
        global $userdata;
        get_currentuserinfo();
        $username = $userdata->user_login;
        $url = 'http://my.url.org/mentions/' . $username;

        wp_redirect( $url );
        exit;
    }
}
add_action( 'template_redirect', 'my_redirect_function' );

You place whatever checks (such as conditional tags) you'd like instead of is_home() check.

share|improve this answer
    
Thank you very much, this worked fantastically. Great explanation and links to conditional tags really helped, I've implemented this and it works! :) –  ameeromar Jan 7 '13 at 0:44
    
@ameeromar Great to hear that. You can always mark the answer as accepted :) –  Mateusz Hajdziony Jan 7 '13 at 0:55
    
is that the little tick? - I've done now... bit of an obscure button! –  ameeromar Jan 7 '13 at 16:09
    
@ameeromar Thanks, that was exactly that. Remember that people will be more eager to answer your questions if you have high accept rate. :) –  Mateusz Hajdziony Jan 7 '13 at 16:11
add comment

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.