0
votes

for page redirection in wordpress plugin m using php header function

my code is

$URL = admin_url('admin.php?page=myaccount&success=yes');
header("location:".$URL);
exit();

it gives me error like this.

Warning: Cannot modify header information - headers already sent by (output started at /home/fusionmark/public_html/wp/wp-admin/includes/template.php:1877) in /home/fusionmark/public_html/wp/wp-content/plugins/JVZoo/includes.php on line 258

2
why are you using this redirection? - sarath
i need to redirect page - Nikhil Musale
Tried like writing a hook like in this link? tommcfarlin.com/wp_redirect-headers-already-sent - Rahul S

2 Answers

0
votes

use wp_safe_redirect() function

 $redirect = admin_url('admin.php?page=myaccount&success=yes');
 wp_safe_redirect($redirect);
 die();
0
votes
$URL = admin_url('admin.php?page=myaccount&success=yes');
header("location:".$URL);
exit();

instead of use:

$location = admin_url('admin.php?page=myaccount&success=yes');
wp_redirect( $location);
exit;

whatever redirect hook you can use but it place before get_header();