redirect generates “Headers already sent” errors.
-
I’ve instantiated my plugin with a shortcode:
add_shortcode('dv_code','dv_code');
If the user is not logged in, I redirect to the login page:
function dv_code(){ $userID=get_current_user_id(); if (!$userID){// 4. $loginURL=wp_login_url(); wp_redirect($loginURL); exit(); } }
However, this generates “Headers already sent” errors:
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/sites/wordpress/wp-includes/class.wp-styles.php:242) in /var/www/html/sites/wordpress/wp-includes/pluggable.php on line 1251
and the login page does not appear.
If I comment out the wp_redirect line, the errors do not appear, but, obviously, neither does the login page.
Is there a way to accomplish this?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘redirect generates “Headers already sent” errors.’ is closed to new replies.