I've created a submenu in wordpress using add_submenu_page:

add_submenu_page(null,'Page Title','Page Title','administrator','page-slug','page-callback');

I want to create another page like this with the condition that the page will be totally blank without creating a new file does wordpress have a function like this?I want it because I want to generate and download an xml file there and if the page has headers and footers the page downloads them too.Any Sugestion? Thank You.


Try something like this: in the load hook, you can ouput your xml code. u

function my_menu_pages() {
    $hook = add_submenu_page(
            null, 'Page Title', 'Page Title', 'administrator', 'sub-menu-slug', function() {
    add_action('load-' . $hook, function() {
        // add your xml code here, 
        // you will get a blank page to start with

add_action('admin_menu', 'my_menu_pages');

Don't try to do this with admin menus/ admin pages. It is going to be a headache. Set up an AJAX API callback and you can have complete control of the output with no worries about any other markup since there won't be any.

function download_xml_wpse_144156() {
  // generate your XML and echo it
add_action('wp_ajax_grab_my_xml', 'download_xml_wpse_144156');
add_action('wp_ajax_grab_my_xml', 'download_xml_wpse_144156');

You can retrieve the XML file with a request to //example.com/wp-admin/admin-ajax.php?action=grab_my_xml. Note that grab_my_xml is the trailing part of the two action hooks. You can set that to whatever you like.

  • I tried but it didn't work for me maybe i am using it wrong – Antonio Papa May 12 '14 at 15:07
  • Yes, you must be using this incorrectly. It does work. – s_ha_dum May 12 '14 at 15:26

Add blank page without wordpress functionality, so you can add your own custom content and controls using your own markup.

add_action( 'admin_menu', 'my_admin_menu' );
        function my_admin_menu() {
            add_menu_page( 'Page Title', 'Menu Name', 'manage_options', 'page_menu_slug', 'page_function', 'dashicons-carrot', 6 );
            add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' );
  • Please edit your answer, and add an explanation: why could that solve the problem? – fuxia Jun 19 '18 at 9:48
  • @fuxia, updated – Muhammad Bilal Jun 19 '18 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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