โดย thatsawan » 25/10/2016 12:01 pm
Filter Hooks
- คือ การเขียนคำสั่งเพื่อการจัดการ หรือ เปลี่ยนแปลงค่าที่ถูกประมวลผลเอาไว้บ้างแล้วก่อนแสดงผลออกมา
ศึกษาเพิ่มเติมได้จากบทความ
สอนสร้าง Plugin WordPress (4) : ทำความรู้จัก Filter Hook
ตัวอย่างการใช้งาน
ตัวอย่างนี้เราจะทำการสั่งให้แปลง ตัวอักษรที่อยู่ใน content (เนื้อหา) เป็นตัวอักษรพิมพ์ใหญ่
โค้ด: เลือกทั้งหมด
add_filter( 'the_content', 'wptest_filterhook' );
function wptest_filterhook ( $content ) {
if ( is_single() ) {
$content = strtoupper( $content);
$content .= '-------------------------> Show Hooks --->' . "";
}
return $content;
}
ผลที่ได้
[b] Filter Hooks[/b]
[list]คือ การเขียนคำสั่งเพื่อการจัดการ หรือ เปลี่ยนแปลงค่าที่ถูกประมวลผลเอาไว้บ้างแล้วก่อนแสดงผลออกมา[/list]
[b]ศึกษาเพิ่มเติมได้จากบทความ [/b]
สอนสร้าง Plugin WordPress (4) : ทำความรู้จัก Filter Hook
[img]http://snap.mindphp.com/index.php?view=2016Oct24_580db766e52e9[/img]
[b]ตัวอย่างการใช้งาน[/b]
ตัวอย่างนี้เราจะทำการสั่งให้แปลง ตัวอักษรที่อยู่ใน content (เนื้อหา) เป็นตัวอักษรพิมพ์ใหญ่
[code=php]
add_filter( 'the_content', 'wptest_filterhook' );
function wptest_filterhook ( $content ) {
if ( is_single() ) {
$content = strtoupper( $content);
$content .= '-------------------------> Show Hooks --->' . "";
}
return $content;
}
[/code]
[b]ผลที่ได้ [/b]
[img]http://snap.mindphp.com/index.php?view=2016Oct24_580db77f362db[/img]