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

I am writing a function to force a redirect when accessing a certain page.

I have done similar things using code like

 if ( is_main_query() && 
       ( is_singular($restricted_post_types)||is_single() ) 
       && ! is_user_logged_in() ) { 

But now I want to target a certain class of pages (profile related pages in the bbpress plugin bc Genesis is destroying them). I don't know what I can use to identify this from an action in the template_redirect hook.

I think anything with the pattern '<baseurl>/forums/user' would catch what I need

share|improve this question
What do you mean by "Genesis is destroying them"? Genesis is removing those pages? – Dan Ștefancu Sep 24 '13 at 22:32
not rly sure why but it's removing most of the markup. twentytwelve theme: imgur.com/HJKeRg3 vs base genesis: imgur.com/SMcmKvS – Damon Sep 25 '13 at 13:03
up vote 1 down vote accepted

If you're trying to catch the pattern '/forums/user', you could use PHP's stringpos function. Something like this should capture what you're looking for:

$url_pattern = "/forums/user";
$requested_uri = $_SERVER["REQUEST_URI"];

if(strpos($requested_uri, $url_pattern) == 0){
    //Your code goes here

Make sure if you have "enforce trailing slashes" set that you use "/forums/user/" as your matching pattern instead. This code isn't tested but should work.

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.