[Resolved] Header hook

Home Forums Support [Resolved] Header hook

Home Forums Support Header hook

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #601428
    Dan

    Hi I added this hook to be added before the <head> section, but I get an error.
    The code is added into th functions.php file
    This is the hook (if the user is not logged in, show a temp page):

    add_action( 'generate_before_header','ds_temp_page' ,1);  
    function ds_temp_page() { ?> 
     <?php if(!is_user_logged_in()){wp_redirect( 'http://www.golancoalition.org/_index.html' ); exit;}?>
    
    <?php }

    The error I get is:

    Warning: Cannot modify header information – headers already sent by (output started at C:\xampp\htdocs\golanco\wp-includes\formatting.php:5103) in C:\xampp\htdocs\golanco\wp-includes\pluggable.php on line 1216

    Any thoughts on why this is happening?

    Thanks,
    Dan

    #601431
    Dan

    Testing in a live server did not produce this error, so it might be related to localhost.

    Dan

    #601588
    Tom
    Lead Developer
    Lead Developer

    You should add that code using one of these methods instead of hooks: https://docs.generatepress.com/article/adding-php/

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.