Reputation: 36554
Wordpress 3.2.2
What's the steps to define a custom link in the wordpress admin such as
http://localhost:8888/wp-admin/admin.php?action=update_posts
so that when this link is accessible by admins, a specific function is executed.
(in the context of a custom wordpress plugin)
EXAMPLE CODE
function my_special_function(){
echo '<div> Hello World </div>';
}
$page_title = "Hello Page Title";
$menu_title = "Hello Menu Title";
$capability = "import";
$menu_slug = "My Menu Slug";
$function = my_special_function;
add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function);
So I have this example code. Now what? And what url should I load to see hello world printed on in the html page?
Upvotes: 0
Views: 3012
Reputation: 16510
You will probably want to use add_menu_page
. That involves two steps. First, you will need to define a function (my_menu_page
in the example below) to create the menu.
// inside plugin file
function my_menu_page ()
{
$page_title = "Hello Page Title";
$menu_title = "Hello Menu Title";
$capability = "import";
$menu_slug = "My Menu Slug";
$function = my_special_function;
add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function);
}
Once you've got that, you will need to register it with WP using the add_action
function and a hook. For an admin menu, the admin_menu
hook is probably appropriate.
// inside plugin file
add_action('admin_menu', 'my_menu_page');
Upvotes: 1