I tried to implement a custom download link in the theme settings, section that will give the users to download there custom settings for the backup. I tried this option

if( isset($_GET['download']) && $_GET['download'] == true ) {

            $data = '';

            if( $upanel !== FALSE ) {
                $data .= serialize(

            $filename = "theme_settings.txt";

            header("Content-Disposition: attachment; filename=".$filename);
            header("Content-Type: application/download");
            header("Pragma: no-cache");
            header("Expires: 0");

            echo $data;

This section working fine and the data is downloaded correctly but its also insert the header html code into the text file. Like all the HTML codes.

Its clue less for me, that without inserting in my text file, hows it comes there? How do i rid from the header html codes.

Downloaded sample:

// Above is unexpected html code from starting
// into the theme_settings.txt file
//Data that i want only

1 Answer 1


Now it is solved, what i have done is, just hook my download script to admin_init hook and its working that i want.

This is the helpful link Headers already sent error with CSV export plugin

Not the answer you're looking for? Browse other questions tagged or ask your own question.