0

Hi this is my code.

add_menu_page('Titlemenu', 'Titlemenu', 'read', 'a-functions', array(&$this,'namefunctions1'));
    add_submenu_page('a-functions', 'title1submenu', 'title1submenu', 'read', 'a-functions', array(&$this,'namefunctions1'));
    add_submenu_page('a-functions', 'title2submenu', 'title2submenu', 'read', 'a-functions2', array(&$this,'namefunctions2'));

I would like to insert a file download when user clicked in the first sub menu.

This is a classic functions for connect submenu to page to be displayed.

    function namefunctions1(){
    <div class="wrap">
     <?php
      include_once(dirname( __FILE__ ) . "/file.htm");
     ?>
    </div>

Thanks for help

0

You can try this.

add_action( 'admin_menu', 'register_my_custom_menu_page' );
function register_my_custom_menu_page() {
    add_menu_page(
        'My Custom Page',
        'My Custom Page',
        'manage_options',
        'my-top-level-slug',
        '',
        'dashicons-menu',
        6
    );
    add_submenu_page( 'my-top-level-slug', 'My Custom Page', 'My Custom Page',
    'manage_options', 'my-top-level-slug', 'custom_subpage_first');
    add_submenu_page( 'my-top-level-slug', 'My Custom Submenu Page 1', 'My Custom 
    Submenu Page','manage_options', 'my-secondary-slug', 'custom_subpage_second');
}

function custom_subpage_first() {
?>
    <div class="wrap">
       <?php include_once(dirname( __FILE__ ) . "/file.htm");?>
    </div>
<?php
}
function custom_subpage_second() {
?>
    <div class="wrap">
       /*Second subpage content */
    </div>
<?php
}
  • Thanks for the reply but I do not understand the differences from my code. The first part of my code is include in functions namefunctionsgeneral(){}. I believe that the code to change is the one in function namefunctions1(){} because now it opens a file on the display and does not download it – wordpress dev02 Nov 30 '18 at 8:44
  • You don't set parent slug of parent menu and the submenu cannot hook it. – Quang Nov 30 '18 at 8:46
  • My full function actually works. If I connect the first submenu to the function I posted, the file is shown on the display. But what I'm looking for was the download and not the opening of the file. – wordpress dev02 Nov 30 '18 at 8:52

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.