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
add_action('template_redirect', 'add_header_redirect', 0, 0);
function add_header_redirect(){
    if( is_page(array(8, 'testimonials', 'Testimonials')) ){
        $default_testimonial = get_permalink( 19 );
        header("Location: $default_testimonial");

this code is in my functions.php file and ONLY works when I am logged into WP. I want all users who go to /testimonials to be redirected. what's going on?

share|improve this question

The problem was with WP-Super-Cache plugin. When I was logged in, it wasn't serving me a cached file, so my template redirect was being executed. Not sure if this is a known liability with WP-Super-Cache.

My solution was to make a template for page-testimonials.php where I set up my PHP redirect. After flushing the cache, the redirect works.

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.