I created a plugin TESTPLUGIN and added it on wordpress admin menu. I can access the plugin from the admin menu just well. The problem I am having is how to link to another file within the plugin. The file members.php is loaded by the add menu callback function. In this members.php I want to add a link to show_member.php load a single member when the name of a member is clicked. Both files are under one directory.

`<a href="<?php echo  plugin_dir_url(__FILE__).'show_member.php?id=4';?>">John Smit`h</a>
the url resolves to  **http://localhost/mywebsite/wp-content/plugins/myplugins/views/members.php** which is the correct path of show_member.php

But am getting this error message when I click the link: Uncaught Error: Call to undefined function plugin_dir_path() in C:\xampp\htdocs... I have also tried plugins_url() but got the same error. Can someone guide how I could link to another file within my wordpress plugin. What an I doing wrong? Thanks.

  • 1
    As the error states, the plugin_dir_path() function is not defined (doesn't exist) when your code attempts to call it. You probably need to wrap your test plugin code in a new function which hooks into WP and runs at a later point.
    – Kevin Vess
    May 28, 2020 at 5:04

1 Answer 1


I solved the problem using the admin_url() wordpress function. In order to link to another page in the plugin or even to another plugin within my project, I did it by passing the registered url to admin_url() function.

<a href="<?php echo  admin_url('admin.php?page=edit-member-page&id='.$id);?>">John Smit`h</a>

//The $id variable passed to the link will be retrieved by use of `$_GET['id']; superglobal on edit_member.php But first url sluf: edit-member-page first should be registered in your plugin or functions.php

in my plugin main

 //add menu call back
    function load_edit_member_page_callback(){
//add admin menu action
//implement register_edit_member_fun function
function register_edit_member_fun(){
    'edit member', //page title
    '', //menu title (I left it blank because  I don't want the menu to appear to users. I just need to make use of the slug to link internally
    'manage_options', //capability
    'edit-member-page', //slug, this is what I passed to hre attribute above
    'load_edit_member_page_callback',//callable function


Hope this helps someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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