- Action
โค้ด: เลือกทั้งหมด
add_action( string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1 )
$tag (string) (Required)
- ชื่อ function หรือ ชื่อเหตุการณ์ที่จะเกิด เช่น save_post หมายความว่า เมื่อมีการกด Save post เราจะเขียนคำสั่งเพิ่มที่นี่ ...
, admin_menu หมายความว่า ต้องการใช้เพิ่ม Menu หน้า Admin ชื่อ ...
ศึกษารายละเอียด $tag ได้ที่ https://codex.wordpress.org/Plugin_API/Action_Reference
- ชื่อของ function ที่เราจะเขียนเพื่อสั่งให้ทำงาน ตอนเหตุการณ์ที่เรา ระบุไว้เกิดขึ้น
ตัวอย่าง
การเพิ่ม Menu ในหน้า Admin
โค้ด: เลือกทั้งหมด
/**
* Register a custom menu page.
*/
function wpdocs_register_my_custom_menu_page(){
add_menu_page(
__( 'Custom Menu Title', 'textdomain' ),
'custom menu',
'manage_options',
'custompage',
'my_custom_menu_page',
'',//plugins_url( 'myplugin/images/icon.png' ),
1
);
}
add_action( 'admin_menu', 'wpdocs_register_my_custom_menu_page' );
/**
* Display a custom menu page
*/
function my_custom_menu_page(){
esc_html_e( 'Admin Page Test', 'textdomain' );
}