Easy redirect with WordPress function wp_redirect

In a recent project, I had to redirect a specific category archive to a WordPress page. I wanted to show special content when people were accessing the category archive page. This is actually pretty easy using the WordPress wp_redirect function.

So I wanted to redirect the category called customers to a specific page. Here is how you can do this.

1. Create a php file in the template folder called category-customers.php. Using this name WordPress will pickup this file automatically when the category archive customers is accessed

2. In the file paste the following code:

<?php wp_redirect( get_permalink(get_option(‘rc4_page_customers’)), 301 ); exit; ?>

You can actually drop this part:


and replace it with a static url. I used this part to determine the url of a page I set in the admin settings for the theme. get_option will find the option called page_customers. This is useful in case the url of the page is changed by the user. So I recommend doing it.

The 301 parameter in the wp_redirect function just tell the search engine and bot the page has been moved permanently.

That’s it, pretty easy. For more info on wp_redirect, visit this link: http://codex.wordpress.org/Function_Reference/wp_redirect

2 Responses


Good day Guillaume,
I think this is exactly what I am looking for.
google indexed a bunch of category archive pages, and I really don’t want people going to them.. I would like to redirect them to the home page.
I looked for the “template” folder.. but could not find it anywhere.
Your thoughts on how I can fix this?
Thanks so much.


These special rules can be both positive and negative. For example, you can match a URL when the user is logged in (and be redirect to one URL), or when the user is not logged in (and be redirected to another URL). This makes it very easy to create custom rules where users are redirected if they are using a particular browser, or if they came from a particular website.

Leave Your Response

* Name, Email, Comment are Required