3
votes

I want to add custom menu and sub-menu to Wordpress admin area. I read some info about it in Codex and I added menus using the function below, which I placed in my theme's functions.php

add_action( 'admin_menu', 'restaurant_menu' );
function restaurant_menu() {
add_menu_page( 'Restaurants Admin Page', 'Restaurants', 'manage_options', get_template_directory() . '/inc/restaurants.php', 'restaurants_admin_page', 'dashicons-format-aside', 6  );

The menu is added to the Wordpress admin sidebar, but I when I'm going that page it goes to the next link:

http://site.ge/wp-admin/admin.php?page=home%2Fbmtbow%2Fpublic_html%2Ftesting%2Fwp-content%2Fthemes%2Fmytheme%2Finc%2Frestaurants.php

but there is no any content, like it is not pointed to the right PHP file.

Am I doing something wrong? and could you help me to solve this problem?

1
you should look at get_template_directory() functionSamvel Aleqsanyan

1 Answers

2
votes

The add_menu_page function doesn't seem to accept a php file as an argument for content. But it does take a function name. You can call your php file with the content in a function, then pass that function as an argument to add_menu_page. (As a side point, you might have the order of your arguments mixed up. The slug is supposed to be 4th, not 5th.) More information about add_menu_page() and it's arguments can be found here.

Try this:

add_action( 'admin_menu', 'restaurant_menu' );
function restaurant_menu() {
    add_menu_page( 'Restaurants Admin Page', 'Restaurants', 'manage_options', 'restaurants_admin_page', 'restaurant_admin_page_contents', 'dashicons-format-aside', 6  );
}
function restaurant_admin_page_contents(){
    include get_template_directory() . '/inc/restaurants.php';
}