I am trying to the redirect on a cart page using a bellow code but,I am not able to redirect on cart page .
wp_redirect("'.home_url('cart').'");
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityPlease use get_page_by_path
wp_redirect( get_page_by_path( 'cart' ) );
exit();
echo "'.get_page_by_path('cart').'";
The function never runs.
Oct 23, 2013 at 20:25
die/exit
at the end or around the function.
"'.foo().'"
will break. For the future: Please test your code before posting something that breaks. Else you'll quickly get a lot of downvotes and loose reputation points and the capabilities.
get_page_by_path()
returns a WP_post
object of the page and not a URL to the page. To get the URL to a page by name, use get_permalink(get_page_by_path($pagename))
Try it like the following. The exit()
is necessary to stop other code from running and redirect right there.
exit( wp_redirect( home_url( "cart" ) ) );