- พูดให้เข้าใจๆ ง่ายๆ มันก็คือการเพิ่ม Box ของฟิลด์ใน Post type ต่างๆ โดยสามารถจะระบุได้ว่าจะว่าง box นี้ที่ตำแหน่งใหน
โค้ด: เลือกทั้งหมด
add_meta_box( string $id, string $title, callable $callback, string|array|WP_Screen $screen = null, string $context = 'advanced', string $priority = 'default', array $callback_args = null )
โค้ด: เลือกทั้งหมด
function custom_meta_box_markup()
{
echo 'hello';
}
function add_custom_meta_box()
{
add_meta_box("demo-meta-box", "Custom Meta Box", "custom_meta_box_markup", "post", "side", "high", null);
}
add_action("add_meta_boxes", "add_custom_meta_box");
* "side", ตำแหน่งที่ต้องการ
* "high" ระดับในหน้าเเสดงผล
ผลที่ได้
ตัวอย่างการใช้งาน
โค้ด: เลือกทั้งหมด
function custom_meta_box_markup()
{
echo '<label for="my_meta_box_text">Text Label</label>
<input type="text" name="my_meta_box_text" id="my_meta_box_text" />';
}
function add_custom_meta_box()
{
add_meta_box("demo-meta-box", "Custom Meta Box", "custom_meta_box_markup", "post", "side", "high", null);
}
add_action("add_meta_boxes", "add_custom_meta_box");
ศึกษาเพิ่มเติมที่นี่
https://developer.wordpress.org/referen ... _meta_box/