BuddyDev

Search

[Resolved] CSS to hide Gallery tab throws Headers Already Sent error

  • Participant
    Level: Initiated
    Posts: 12
    Panos on #14792

    WordPress 4.9.5, BuddyPress 2.9.4

    So I’m using the below code in my bp-custom.php to hide the Gallery tab (and the Friends tab but that’s unrelated) because I only utilize the Photos gallery so I don’t want it to get confusing showing both the Gallery and the Photo tabs. The problem occurs when user clicks on View under the gallery pic to get inside the gallery. I get “Warning: Cannot modify header information – headers already sent by (output started at /home/user/site.com/wp-content/plugins/bp-custom.php:146) in /home/user/site.com/wp-includes/pluggable.php on line 1216”.

    Any idea how to fix this?
    Thanks in advance.

    function remove_nav_items() {
        if ( ! bp_is_my_profile() && !is_super_admin()) {
    		bp_core_remove_nav_item( 'friends' );
    		echo '<style>li#gallery-my-gallery-personal-li {Display: none;} </style>';        
    	}
    }
    add_action( 'bp_setup_nav', 'remove_nav_items',301);
  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #14793

    Hi Panos,
    In WordPress/BuddyPress redirects happen at template_redirect/bp_template_redirect.

    In order to allow the redirects/sending cookies or setting up session, the headers should not be sent before these.

    In your case, you are sending the output too early and that is leading to issue.

    Please hook to ‘wp_head’ and it will work fine.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 12
    Panos on #14795

    This worked. Thank you Brajesh!
    The code I used (I decided to remove it even when viewing one’s own profile):

    //Remove Gallery tab 
    function remove_gallery_tab() {
        if ( !is_super_admin()) {
    	echo '<style>li#gallery-my-gallery-personal-li {Display: none;} </style>';        
    	}
    }
    add_action( 'wp_head', 'remove_gallery_tab');
  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #14802

    You are welcome.

    Thank you for sharing the updated code.

    Regards
    Brajesh

The topic ‘ [Resolved] CSS to hide Gallery tab throws Headers Already Sent error’ is closed to new replies.

This topic is: resolved