관리자 페이지에 자신만의 메뉴를 추가하고 싶을때는,

add_menu_page() 함수를 사용하면 된다.

 

공식 문서를 확인해보면, (https://developer.wordpress.org/reference/functions/add_menu_page/)

add_menu_page( 
    string $page_title, 
    string $menu_title, 
    string $capability, 
    string $menu_slug, 
    callable $function = '', 
    string $icon_url = '', 
    int $position = null 
)

 add_menu_page 함수는 위와 같은 파라미터를 사용할 수 있다.

 

각 파라미터를 설명해보면

$page_title : add_menu_page 함수로 만들어진 페이지의 제목

$menu_title : 관리자 페이지에 표시될 메뉴 제목

$capability : 해당 메뉴를 볼 수 있는 사용자 권한  (https://wordpress.org/support/article/roles-and-capabilities/

$menu_slug : 만들어질 페이지의 slug, slub는 영어소문자, 숫자, -(하이픈) 으로만 구성 된다.

$function : 만들어질 페이지에 출력될 내용. 함수로 구현해도 된다. (예: echo "HIHI"; )

$icon_url : 해당 메뉴의 아이콘

$position : 해당 메뉴가 표시될 위치 설정  (아래 참조, 해당 숫자 사이사이를 입력하면 해당 메뉴 사이에 위치하게 된다.)

Default: bottom of menu structure #Default: bottom of menu structure
2 – Dashboard
4 – Separator
5 – Posts
10 – Media
15 – Links
20 – Pages
25 – Comments
59 – Separator
60 – Appearance
65 – Plugins
70 – Users
75 – Tools
80 – Settings
99 – Separator


For the Network Admin menu, the values are different: #For the Network Admin menu, the values are different:
2 – Dashboard
4 – Separator
5 – Sites
10 – Users
15 – Themes
20 – Plugins
25 – Settings
30 – Updates
99 – Separator

 

실 사용 예제

 function testPage() {
	 add_menu_page(
		 '테스트에용',
		 '테스트',
		 'manage_options',
		 'test-test',
		 'testPageFunction',
		 'dashicons-admin-generic',
		 81
	 );
 }
 add_action( 'admin_menu', 'testPage');

 function testPageFunction() {
	 get_template_part( 'admin-template-parts/test', 'test'  );
 }

위와 같은 함수를 현재 사용하고 있는 테마 폴더에 있는 functions.php 에 추가해준다.

그럼 '테스트' 라는 메뉴가 관리자 페이지에 생성되고,

해당 '테스트'라는 메뉴를 클릭하면,

해당 테마 폴더의 'admin-template-parts'라는 폴더안에 test-test.php 파일이 실행되면서 표시된다.

+ Recent posts