สอนสร้าง Plugin WordPress (8) : ตัวอย่างการใช้งาน add_filter ( Filter Hooks )

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: สอนสร้าง Plugin WordPress (8) : ตัวอย่างการใช้งาน add_filter ( Filter Hooks )

Re: สอนสร้าง Plugin WordPress (8) : ตัวอย่างการใช้งาน add_filter ( Filter Hooks )

โดย mindphp » 25/10/2016 9:53 pm

รวมกระทู้ บทความสอนสร้าง Plugin WordPress
https://www.mindphp.com/forums/viewtopic ... 25&t=36079

สอนสร้าง Plugin WordPress (8) : ตัวอย่างการใช้งาน add_filter ( Filter Hooks )

โดย 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;

} 
ผลที่ได้
รูปภาพ

ข้างบน