0

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').'");
1

Please use get_page_by_path

wp_redirect( get_page_by_path( 'cart' ) );
exit();

Reference link for get page by path

| improve this answer | |
  • You might want to test that weird quoting: echo "'.get_page_by_path('cart').'"; The function never runs. – Charles Clarkson Oct 23 '13 at 20:25
  • Man, please! Start using the WYSIWYG editor! Click the edit link and fix it. I already commented on your other answers with the exact same notes. Aside from that @CharlesClarkson is right and aside from that, you're missing the die/exit at the end or around the function. – kaiser Oct 24 '13 at 4:12
  • 1
    I removed the downvote and fixed your code. "'.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. – kaiser Oct 24 '13 at 14:21
  • 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)) – Guss Mar 7 '17 at 12:40
1

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" ) ) );
| improve this answer | |

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