Forums

[resolved] Called dashbooard menu function (7 posts)

  1. peterjharrison
    Member
    Posted 2 years ago #

    Hi,

    Was woondering if anyone knows of a way I can call the [_wp_menu_output] function from the front end of my website.

    It is currently located in [wp-admin/menu-header.php] file but I would like to call it from my template.

    I think this is one for the more advnaced WordPress developers, but any help would be cool.

    Regards
    Pete

  2. Mark / t31os
    Moderator
    Posted 2 years ago #

    Have you tried including the file?..

    You can't call a function from a file that's not been loaded, so try an include first, then see if your function call works..

  3. peterjharrison
    Member
    Posted 2 years ago #

    Hi,

    Thanks for your reply.

    I don't think including the file is going to work there seems to be far to many includes that I will need.

    I've been looking further into the code and what I actually want to use is the $menu and $submenu arrays that are used to build the admin menu in te dashboard.

    Do you know if there is a way of accessing these from within a plugin?

    Regards
    Pete

  4. Mark / t31os
    Moderator
    Posted 2 years ago #

    include( 'wp-admin/menu.php' );

    $menu and $submenu are defined there, include it and you'll have access to the vars..

    Also, if preferred, you hook an action onto..

    _admin_menu

    ..instead of the include..

    You you will likely need to globalise the $menu and $submenu vars when using the action hook..

    add_action( '_admin_menu' , 'example' );
    function example() {
    global $menu, $submenu;
    ..

    ;)

  5. peterjharrison
    Member
    Posted 2 years ago #

    Hi,

    Thanks for your reply.

    When I try and include the menu.php file I get the following error:

    Warning: Invalid argument supplied for foreach() in /mnt/local/home/pjharrison/peterjharrison.me/wp-admin/menu.php on line 38

    I think it has something to do with the $wp_taxonomies array, any ideas?

    Regards
    Pete

  6. Mark / t31os
    Moderator
    Posted 2 years ago #

    It's because when you include the file, there's no $wp_taxonomies var for it to loop over... where as when the file is usually included that var is present...

    What do you think you should do ? ... it's your code ... i can't tell you how to write it .. ;)

  7. peterjharrison
    Member
    Posted 2 years ago #

    Hi

    Thanks for your help.

    I guess I'll have to try and find out what populates the $wp_taxonomies array and see if it will effect what im trying to do if I push it through as blank.

    Regards
    Pete

Topic Closed

This topic has been closed to new replies.

About this Topic