My problem is very similar to the thread Cannot modify header information in wordpress. Unfortunately, it is not marked answered there and cpicko's answer helped me understand the problem but I haven't been able to solve it.
I am trying to redirect a subscriber to home page if he tries to log in his backend profile. I want to do this because I want my site to be totally front-end driven and professional. For this wordpress has example code on http://codex.wordpress.org/Plugin_API/Action_Reference/admin_init. It is as below
function restrict_admin_with_redirect() {
if ( ! current_user_can( 'manage_options' ) && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
wp_redirect( site_url() );
exit;
}
}
add_action( 'admin_init', 'restrict_admin_with_redirect', 1 );
When I paste this in my functions.php, it does the redirect but then breaks after header with below error.
"Warning: Cannot modify header information - headers already sent by (output started at /***/wp-content/themes/twentytwelvechild/headerwithquotes.php:15) in /***/wp-includes/pluggable.php on line 1121"
But these files/lines are not modifies by me at all. They are just like fresh wordpress install. The example also is exactly like in wordpress site. This works fine in my dev site but doesn't work when I migrate to production
Cpicko mentioned in that thread that javascript might help. How can I use javascript in this scenario when pages are wordpress default pages and not that build in website. Can someone please help me with this redirection. I would really appreciate it.
Sorry, but my English isn't very good. I had the same problem
After 8 hours i fixed this issue. I just add
;
at the end of the first line<?php;
ofwp-config.php
. That's all. Now, I can log-in as wordpress admin.Hope this helps...
this could happen due to several reasons. i faced to this issue few days ago when i tried to add a new function to my function.php file. here is the fix i found from the google
wp-config.php issue
functions.php issue
Source : http://www.mytrickpages.com/2013/11/how-to-fix-wordpress-error-cannot-modify-header-information.html