WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a download link for my plugin using add_submenu_page. When the link is clicked it gathers some files into a zip, then outputs the contents to the browser like so:

header('Content-Type: application/zip');
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename="file.zip"');

The issue is that wordpress by default wraps everything in it's admin theme. Is there a flag or something I can set to tell wordpress that for this particular page I don't want it to out the admin interface?

Edit: Here is the code I used to generate the submenu page:

  add_action('admin_menu', array($this, 'add_download_page'));

  function add_download_page() {
      , 'Download Newsletter' 
      , 'Download Newsletter'
      , 'manage_options'
      , 'spn_download'
      , array($this, 'do_download')
share|improve this question
Show the code you are using to create this submenu page. – brasofilo Jan 17 '13 at 20:09
up vote 1 down vote accepted

I think you'll have to hook an earlier action and check if your subpage is being loaded, when the function to render the subpage happens it's too late to send headers. Your subpage's rendering function could just be blank because the earlier action would override it. I tried this with a subpage of themes.php and it seemed like it would work:

function wpa82041_do_download(){
    global $pagenow;
    if( 'themes.php' == $pagenow
    && 'spn_download' == $_GET['page'] ){
        // do your download stuff

add_action( 'admin_init', 'wpa82041_do_download' );
share|improve this answer
Wow, very clever, that did exactly what I needed. Thanks. – greatwitenorth Jan 17 '13 at 22:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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