Do you know that WordPress have a built-in function to redirect users to a specific url? It is called wp_redirect(). Many users don’t know it, but you can also create 301 redirections with that useful function.
Do you know that WordPress have a built-in function to redirect users to a specific url? It is called wp_redirect(). Many users don’t know it, but you can also create 301 redirections with that useful function.
To create a 301 redirection within WordPress, you just have to add the 301 argument to the function:
<?php wp_redirect('http://www.wprecipes.com', 301); ?>
The above code will redirect anyone on my blog. Don't hesitate to use it
24 Responses
And this works anywhere? It’s not restricted to being before anything is output, as header() is?
@redwall_hp: No, it must be used before anything has been printed out. I have some problem with that function, and I must admit afterwards that it wasn’t a very good idea for a recipe. Anyways, let’s hope it will be helpful to someone
Oh well. So I’m guessing the function is just a friendlier facade for header()?
That’s simple
Didn’t know there was a built in function. Not sure what I could use it for..
But always good to know all the features.. or most..
There is a plugin Redirection (http://urbangiraffe.com/plugins/redirection/) that takes care of redirections.
Redirections are useful if there are errors or changes in urls of your site. I use Google Webmaster Tools – dashboard to see if there are any errors (URL not found). These I correctusing Redirection to point to the correct URL
@fahirsch: I use this plugin, it is a must have in my opinion. Maybe i’ll talk about it on a forthcomming recipe.
thank you, i am gonna try it.
nice info, i’ll try it too.
I really don’t know this word press function for the redirect, thanks to tell us about it.
Great, I will use the code, Thank you.
wow, i never knew that before. thanks, i am gonna try it asap.
Great, i hope it works for me. I have much changes and now the bots are going to pages where are not longer available.
very impressive, thanks for sharing this. keep up the great work.
greetjes
Nice info, i’ll try it too.
Thats simple, thanks for sharing.
And if you have several urls to redirect?
This is a nice tip, i will test it.
Great, I will use the code, Thank you.
cu
Super tip! Thanks for this feature! Greetings
Trackbacks: