M
M
mrWan2018-02-03 16:21:40
WordPress
mrWan, 2018-02-03 16:21:40

How do I redirect to the same page in Wordpress?

here is my code part in function.php:

if (!empty($_POST['send_email']) and !empty($_POST['send_mess'])):
  wp_mail('[email protected]', 'письмо с сайта', $_POST['send_mess']); //, $headers, $attachments
  wp_redirect( get_permalink() );
  exit;
 	endif;
}

as I understand it, the get_permalink () function has not yet had time to be determined, I need to somehow do it dynamically, because I have the form connected on several pages.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2018-02-03
@mrWan

Do you initially have code sticking out in functions.php, not defined in a callback function that is hung on some kind of hook? Then you are doing everything wrong. Your code is executed every time any page is loaded , both on the front and in the admin. And it is executed when the theme files are loaded. Hang the code on template_redirect. Instead of get_permaink use $_SERVER['HTTP_REFERER'].

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question