Pooja Kshatriya Pooja Kshatriya - 2 months ago 7
PHP Question

How to redirect page in Wordpress by coding

I am using WordPress twentysixteen theme. There I have created a page template. In that I have created a login form. I want to redirect a user to the next page after successful login.

I tried:

header('Location: http://website.com/my-page/');
wp_redirect(get_page_by_title('My Page'));


saying error


headers already sent

Answer

You can workarond this problem by redirecting page via javascript

echo '<script type="text/javascript">window.location = "/my-page/"</script>';
exit;
Comments