
內容簡介
「Shortcode Callback」這個外掛允許您在使用 shortcode 的地方執行任意的 PHP 代碼,只要使用 [callback] shortcode 即可。
用法如下:
使用以下 shortcode 執行 someFunction(),並插入其回傳結果:
[callback function=”someFunction”]
範例:使用以下 shortcode 包含一個 PHP 檔案(路徑相對於 WordPress 的 ABSPATH),然後在使用 shortcode 的地方插入執行 someFunction() 的結果:
[callback include=”custom/filetoinclude.php” function=”someFunction”]
範例:使用以下 shortcode 包含一個 PHP 檔案(路徑相對於 WordPress 的 ABSPATH),然後向 someFunction() 傳遞一個參數,在使用 shortcode 的地方回傳結果:
[callback function=”someFunction” include=”custom/filetoinclude.php” param=”something”]
使用該外掛呼叫類別/方法的格式與上面完全相同,只需在 shortcode 的「function」屬性中指定「class::method」即可。
[callback function=”someClass::someFunction” include=”custom/filetoinclude.php” param=”something”]
這裡有一個範例(並含有 PHP 代碼)。
外掛標籤
開發者團隊
原文外掛簡介
The Shortcode Callback plugin allows you to use a [callback] shortcode to execute arbitrary PHP code wherever the shortcode is used.
Usage
Execute someFunction() and insert whatever it returns with the following shortcode:
[callback function=”someFunction”]
Example shortcode to include a PHP file (the path is relative to WordPress’ ABSPATH), then insert the results of someFunction() where you used the shortcode:
[callback include=”custom/filetoinclude.php” function=”someFunction”]
Shortcode example that includes a PHP file (the path is relative to WordPress’ ABSPATH), then passes a paramter to someFunction() and returns the results where you used the shortcode:
[callback function=”someFunction” include=”custom/filetoinclude.php” param=”something”]
The format to call a class/method with the shortcode is exactly the same as above, except you specify the class::method in the “function” attribute of the shortcode.
[callback function=”someClass::someFunction” include=”custom/filetoinclude.php” param=”something”]
There is an example (with PHP code) over here.
