Is there any way to add absolute path for add_menu_page function?

I am creating a plugin for add menu option to WordPress admin and using below function for that:

<?php add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); ?>

But I would like to add absolute path for menu option in the place of $menu_slug.

enter image description here

please see the screen shot, I have created both ” Header and footer ” using add_menu_page function. I would like to give absolute path for both header and footer. I know plugins are available for this but I am creating my plugin with different functionality.

1 Answer
1

I don’t think there is a clean way to put arbitrary link into the menu item. At most you could change it with JavaScript after the fact.

However there is an edge case that allows you to load plugin file there.

  1. Pass as $menu_slug argument a path to a plugin file relative to plugins directory, for example plugin-folder/boo.php.
  2. Omit $function argument.
  3. This will generate link like admin.php?page=plugin-folder/boo.php.
  4. Following the link will load the file as content of admin page.

There isn’t actually much benefit over just using callback for output. But from technical point of view this is about as close as possible to including a file in there.

Leave a Comment