Bạn đang xem: Using wp_redirect to redirect wordpress pages
wp_redirect( "http://www.example.com/contact-us", 301 );
so here is my question.
Let"s say I have a page called "https://www.example.com/contact-us-3/" that needs lớn redirect lớn "https://www.example.com/contact-us/".
Or I should say I really want the redirect to happen regardless of http or https, www or non-www.I am want "/contact-us-3/" to redirect to "/contact-us/" page.
Does that mean I have to lớn put the following code inside the wordpress contents? Where vì I exactly put the code? function.php in the child theme? I vày I specify the page that needs to be redirected? or I bởi have to lớn create a page "/contact-us-3/" và put the code in the page?
Also, vì I have to lớn put the fully qualified domain name name url?
php wordpress .htaccess redirect url-redirection
asked Dec 21, 2016 at 17:03
34911 gold badge44 silver badges2020 bronze badges
showroom a comment |
1 Answer 1
Sorted by: Reset to mặc định
Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
You may want khổng lồ put your redirect code into a callback function that is tied khổng lồ the template_redirect hook. Put code similar lớn the following in the functions.php file of your theme. The function named "some_condition" (which you write) will determine if the page should be redirected or not.
add_action( "template_redirect", "my_callback" );function my_callback() if ( some_condition() ) wp_redirect( "http://www.example.com/contact-us", 301 ); exit();
answered Dec 21, năm nhâm thìn at 17:44
11955 bronze badges
địa chỉ cửa hàng a comment |
Thanks for contributing an answer to lớn Stack Overflow!Please be sure khổng lồ answer the question. Provide details & share your research!
But avoid …Asking for help, clarification, or responding khổng lồ other answers.Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
Sign up using Google
Sign up using Facebook
Sign up using thư điện tử and Password
Post as a guest
email Required, but never shown
Post as a guest
Required, but never shown
Post Your Answer Discard
Not the answer you're looking for? Browse other questions tagged php wordpress .htaccess redirect url-redirection or ask your own question.
The Overflow Blog Featured on Meta
Redirect from Wordpress to lớn Laravel if user logged into Laravel?
How to manage a redirect request after a jQuery Ajax call
How vị I redirect khổng lồ another webpage?
How do I make a redirect in PHP?
How can I add a PHP page to lớn WordPress?
Redirect from an HTML page
htaccess redirect to lớn https://www
Redirect non-www khổng lồ www WITHOUT forcing https
How to bởi vì "Two 301 Redirects to lớn One 301 Redirect" Wordpress
Hot Network Questions more hot questions
Subscribe lớn RSS
Question feed khổng lồ subscribe to lớn this RSS feed, copy and paste this URL into your RSS reader.
Stack Exchange Network
Site thiết kế / biệu tượng công ty © 2022 Stack Exchange Inc; user contributions licensed under CC BY-SA. Rev2022.9.9.42970