How do I make the redirect in Wordpress on the same page?

here is my piece of code in function.php:
if (!empty($_POST['send_email']) and !empty($_POST['send_mess'])):
 wp_mail('', 'letter from website', $_POST['send_mess']); //, $headers, $attachments
 wp_redirect( get_permalink() );

as I understand it, the function get_permalink() has no time to decide, I should like to do this dynamically, because the form I used on multiple pages.
June 8th 19 at 16:31
1 answer
June 8th 19 at 16:33
You initially code in and out functions.php not defined in callback function, which is hung on a hook? Then you're doing it wrong. Your code runs every time you load any pageas front, and in the admin area. And he performed when loading theme files. Hang the code on template_redirect. Instead get_permaink use $_SERVER['HTTP_REFERER'].
thank you - edwina_Weissnat commented on June 8th 19 at 16:36

Find more questions by tags WordPress