• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

GhazaliTajuddin.com

Another Kuantan Blogger

  • Home
  • Blog
    • Kuantan
    • Foods
    • Technology
    • Health
  • Stock Photography
    • Senarai Microstock Agency
    • Membuka akaun contributor Shutterstock.com
    • Tips untuk 10 keping gambar pertama Shutterstock.com
    • Mengapa Shutterstock.com reject gambar / submission
    • Model Release
    • Bagaimana withdraw earning daripada Fotolia
    • Bagaimana untuk mengisi keyword kepada imej dengan menggunakan Adobe Photoshop

echo

Pembangunan WordPress Plugin Yang Menggunakan Shortcodes

May 16, 2016 by ghazalitajuddin

Develop pulgin yang menggunakan shortcodes ini perlu tahu beberapa perkara

  1. Widget text tak support shortcodes secara default.
    • Jika anda ingin menggunakan shortcodes pada bahagian widget. Pasti anda akan gunakan Widget Text.
    • Tetapi secara defaultnya, widget text tak support shortcodes.
    • Anda perlu aktifkan seperti berikut
      //Remove the filter if it already exists
      remove_filter('widget_text', 'do_shortcode');
      
      //Add the filter to apply the shotcode action to widget text
      add_filter('widget_text', 'do_shortcode');
  2. Guna return, bukan echo.
    • Sekiranya anda ingin memaparkan suatu keputusan melalui shortcodes anda, anda akan perasan sekiranya menggunakan echo, hasil keputusan berkenaan akan di paparkan sebelum atau diluar daripada kawasan <div> sepatutnya.
    • Untuk itu elakkan gunakan echo, kerana secara asasnya formatnya adalah menggunakan return.

      Note that the function called by the shortcode should never produce output of any kind. Shortcode functions should return the text that is to be used to replace the shortcode. Producing the output directly will lead to unexpected results. This is similar to the way filter functions should behave, in that they should not produce expected side effects from the call, since you cannot control when and where they are called from.

    • Contohnya seperti berikut
      function callmyshortcode() {
      return 'This is correct';
      }
      add_shortcode('correctshortcode', 'callmyshortcode');
      
      /*--------------------
      function callmyshortcode() {
      echo 'This is wrong';
      }
      add_shortcode('wrongshortcode', 'callmyshortcode');
      --------------------*/

Reference: Wordperss Function Reference/add shortcode

Filed Under: General Tagged With: echo, return, shortcodes, wordpress

Primary Sidebar

“Solat. Sabar. Syukur. Senyum. Sedekah.”

For Collaboration, Events & Review, kindly contact me at +6016[-]9212092 or click Whatsapp button on this page.

Sponsor

Recent Posts

BadMethodCallException Method Illuminate\Database\Eloquent\Collection::roles does not exist.

User Roles And Permissions Without Package Laravel 10

Laravel Many To Many Relationship

Makan malam bersama keluarga di Awangan Palace

Sarapan pagi di Warung Gulai Kawah

Recent Comments

  • helmi on Personal Tips Berhenti Merokok
  • ghazalitajuddin on Personal Tips Berhenti Merokok
  • helmi on Personal Tips Berhenti Merokok
  • ghazalitajuddin on Nasi Lemak Kukus Restoran Zaman. Otai masih berbisa.
  • ghazalitajuddin on Air tangki radiator Proton Exora cepat kering? Cuba tukar penutup radiator!
  • Mal on Nasi Lemak Kukus Restoran Zaman. Otai masih berbisa.
  • Firdaus on Air tangki radiator Proton Exora cepat kering? Cuba tukar penutup radiator!

My Link

  • Takaful Insurance Web

JJCM

Kopi Vietnam di Kuantan Pickers

Breakfast di De Aisyah Kuantan

Kopi Acah-acah Diet

Demong Cafe Kampung Raja Besut

Minuman Diet

Tags

bebas rokok berhenti merokok breakfast Controller Framework Gezzeg Photography & Design health jalan-jalan cari makan jalan-jalan cari makan kuantan jjcm jjcm kuantan Jurufoto Kuantan Kuantan Kuantan Photographer kuantan programmer kuantan web developer kuantan webmaster laravel merokok merbahayakan kesihatan model MVC nikmat rokok OOP Pahang Pahangtourism pahang tourism Photo Manipulation PHP rajalanun retired smoking revisit pahang 2018 shutterstock stop smoking stop smoking tips stop smoking withdrawal symptom tips tips berhenti merokok View visit malaysia 2020 visit pahang visitpahang white wordpress yii Yii Framework

Recent Posts

  • BadMethodCallException Method Illuminate\Database\Eloquent\Collection::roles does not exist.
  • User Roles And Permissions Without Package Laravel 10
  • Laravel Many To Many Relationship
  • Makan malam bersama keluarga di Awangan Palace
  • Sarapan pagi di Warung Gulai Kawah

Copyright © 2025 — Ghazali Tajuddin • All rights reserved. •