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 have a plugin which do very simple task...

if ( $_SERVER["REQUEST_URI"] === '/foo' )
{
   // How to display the content of page of ID = 3, without using wp_redirect()
}

So the url is staying at /foo, but show the content of page ID = 3

Any idea?

share|improve this question
add comment

1 Answer 1

If /foo doesn't exist as a page, you can map the URI to another page with a rewrite rule:

function wpa_rewrite(){
    add_rewrite_rule(
        'foo/?$',
        'index.php?page_id=3',
        'top'
    );
}
add_action( 'init', 'wpa_rewrite' );
share|improve this answer
    
Seems that I need to flush the rewrite rule after adding it? –  Yoga Jun 25 '13 at 15:26
    
@Yoga - yes, see the plugin example on flush_rewrite_rules() to flush on plugin activation. –  Milo Jun 25 '13 at 16:04
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.