Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

So i'm trying to create a WordPress plugin and I've created some menu pages using this provided function:

add_submenu_page('my_plugin_menu', 'Edit record page', 'Edit record page', 'manage_options', 'edit_record_page', array(&$this, 'display_edit_record_page');

and when I go to the page I notice on the address bar on the browser it reads something like this:

http://mydomain.com/wp/wp-admin/admin.php?page=edit_record_page

What I want to do is to be able to link this page but I find I have to hardcode the link for lack of a better way of doing it and I'm working on a dev site. So I was wondering how I could dynamically generate the link I saw on my browser so that when I copy this plugin code onto the production server it will work. Namely, is there a WordPress function that will generate the link portion of the submenu page create.

page=edit_record_page

Also, if I want to append query strings to the to the link is it as simple as adding it manually like so:

http://mydomain.com/wp/wp-admin/admin.php?page=edit_record_page&rec_id=1

or is there an appropriate WordPress function for doing that too?

share|improve this question
add comment

2 Answers

up vote 13 down vote accepted

admin_url() gets you the correct administration page URL (and network_admin_url() to get a network administration page URL)

Optionally, you can use add_query_arg() to append arguments to an URL, using an associative array:

$page       = 'edit_record_page';
$rec_id     = 1;
$record_url = add_query_arg(compact('page', 'rec_id'), admin_url('admin.php'));
share|improve this answer
add comment

<a href="admin.php?page=edit_record_page">Link Text</a>

and

<a href="admin.php?page=edit_record_page&rec_id=1">Link Text</a>

share|improve this answer
    
This works, however can you show an example of using admin_url(); inline like this? –  BenRacicot Jan 31 at 18:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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