Forums

Admin menu links are broken after adding my own menu page (2 posts)

  1. yehkemon
    Member
    Posted 1 year ago #

    I add my own page like this:

    add_menu_page("My Controls",
                  "My Controls",
                  "manage_options",
                  "../wp-content/plugins/myplugin/my-controls.php",
                  "");

    Now, when I click on the original admin menu links from my menu page, the links are relative to my folder - they don't work.

    How do I fix this?

  2. yehkemon
    Member
    Posted 1 year ago #

    I've tried using this code instead of directly referencing a php page:

    add_menu_page("My Controls",
                  "My Controls",
                  "manage_options",
                  "my-controls",
                  array(&$this->my_templates, 'my_controls'));

    Now the links to other admin menus work fine, as my menu page is rendered as admin.php?page=my-controls, so the current working directory is still /wp-admin.

    However, this is less flexible as I now rely on admin.php to set up the page elements for me. For example, admin-header.php is added by admin.php before I have a chance to use wp_enqueue_scripts.

    I can enqueue scripts by hooking into add_action('init', 'enqueue_my_scripts'), but this is elsewhere in my code, and is not nice and modular.

    Hope these details aren't too confusing, and I appreciate any advice you may have!

Topic Closed

This topic has been closed to new replies.

About this Topic