I added a template_redirect to my functions.php file, which redirects private staff members to a "Staff No Longer Available" page. However, my code only works when I am logged in. Am I missing something?

function redirect_private_staff() {
  if ( is_singular( 'our_providers' ) && 'private' == get_post_status() ) {
      wp_redirect( 'https://www.nystromcounseling.com/provider-profile-unavailable/', 301 );

add_action( 'template_redirect', 'redirect_private_staff' );
  • The fact that it only works when you're logged in indicates that caching is in play. Possibly a caching plugin? You'll probably need to flush it.
    – vancoder
    Jan 16 at 19:54

1 Answer 1


Based on what you provided, I agree with the comment from @vancoder that caching is likely at play here. If you're not sure how to purge the caching on your site, the easiest approach may be to add a simple query string on the end of the original URL. That usually bypasses caching and loads the page from scratch.

So if your original URL was https://www.example.com/our-providers/, then while logged out, enter this in your browser and see if the redirect works: https://www.example.com/our-providers/?cache-test=123456789

Note that ?cache-test=123456789 is what's added onto the end.

Also, manually setting up redirects through code can become cumbersome very quickly. I'd suggest one of two solutions here:

  1. Utilize a plugin that allows you to add redirects in the admin. My favorite is Redirection, but there are a lot out there.
  2. Check with your hosting provider to see if they offer a way to add redirects within their management tools. Most of the popular ones do.

Good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.