본문 바로가기

워드프레스 관리자 메뉴 추가

web/wordpress by 코나인 2023. 5. 17.
반응형

워드프레스 관리자 메뉴 추가는

add_menu_page, add_submenu_page(필요시) 함수를

admin_menu 액션 태그에 등록하면 된다.

 

theme/functions.php

$title = '가계부';
function my_menu_render() {
  global $title;
  ?>
      <h2><?php echo$title;?></h2>
      My New Menu Page!!
      <?php
}

function my_submenu_render() {
  global $title;
  ?>
      <h2><?php echo $title.' sub';?></h2>
      My New Sub Menu Page!!
      <?php 
}

add_action( 'admin_menu', function () {

  add_menu_page(
    __('My Menu Page'), 
    __('My Menu'),
    'edit_themes',
    'my_new_menu',
    'my_menu_render',
    '', 
  81);

  add_submenu_page(
    'my_new_menu', 
    __('My SubMenu Page'), 
    __('My SubMenu'),
    'edit_themes',
    'my_new_submenu',
    'my_submenu_render');

});

 

 

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 $callback = '', 
  string $icon_url = '', 
  int|float $position = null )
: string

 

add_submenu_page

https://developer.wordpress.org/reference/functions/add_submenu_page/

add_submenu_page( 
  string $parent_slug, 
  string $page_title, 
  string $menu_title, 
  string $capability, 
  string $menu_slug, 
  callable $callback = '', 
  int|float $position = null )
: string|false
반응형

댓글