WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

im trying to redirect the loggedin user to a page i created on the backend, i want to use my index to do so

so, i added a do_action wrapped in an if statement is_user_loggedin() to call my function.

here's the function:

function my_redirect() {
  global $bp;

 if ( $bp->current_component == $bp->root_domain ) {
  bp_core_redirect($bp->current_component == MY_CUSTOM_SLUG  );

but it's not working. The page shows when you navigate to it, but it wont redirect when viewing the root page (index).

Here's whats in the index.php

 <?php if ( is_user_logged_in() ) : ?>

 <?php do_action( 'my_redirect'); ?>

 <?php endif; ?>

Thanks ahead of time :)

share|improve this question
Please remove the part above you describe as "my next Q" and post a second question so that question and answer can be found by Google. – MikeSchinkel Jan 29 '11 at 20:25
Can you show us your 'add_action()' statement? What hook did you use? – MikeSchinkel Jan 29 '11 at 20:27
oh ok :P got it, I updated it – Sin Jan 29 '11 at 23:04
up vote 0 down vote accepted

I think what you're trying to do here is create a custom hook. You should just do this to make it work correctly:

<?php if ( is_user_logged_in() )
    my_redirect(); ?>

There's no need to make it an action if you can use the function directly in your template. Actions are primarily used when you want to alter the behavior of core or you don't want to alter an already existing template.

Since you're creating your own template anyway, just call the function directly to reduce overhead. I would do this before get_header() or any characters are rendered or you will receive a PHP error.

share|improve this answer

Your Answer


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.