- 工信部備案號 滇ICP備05000110號-1
- 滇公安備案 滇53010302000111
- 增值電信業(yè)務(wù)經(jīng)營許可證 B1.B2-20181647、滇B1.B2-20190004
- 云南互聯(lián)網(wǎng)協(xié)會理事單位
- 安全聯(lián)盟認證網(wǎng)站身份V標記
- 域名注冊服務(wù)機構(gòu)許可:滇D3-20230001
- 代理域名注冊服務(wù)機構(gòu):新網(wǎng)數(shù)碼
簡單說 WordPress Shortcode 指的是一些使用[]包含的短代碼,WordPress會識別這些短代碼并根據(jù)短代碼的定義輸出為特定的內(nèi)容。
下面藍隊網(wǎng)絡(luò)為大家介紹一下它的類型,基本概念,函數(shù),這三個方面
Shortcode API 支持幾乎所有可能的組合形式:自關(guān)閉標簽,開放標簽,含有參數(shù)的標簽等。
1 2 3 4 5 6 | [mycode] [mycode foo="bar" id="123" color="red" something="data"] [mycode]Some Content[/mycode] [mycode]<p><a href="http://www.tjdsmy.cn/">HTML Content</a<>/p>[/mycode] [mycode]Content [another-shotcode] more content[/mycode] [mycode foo="bar" id="123"]Some Content[/mycode] |
首先你要去定義一個函數(shù),來處理你定義的 Shortcode,和它的屬性參數(shù)以及引用的內(nèi)容。
1 2 3 4 5 6 | function my_shortcode_func($attr, $content) { // $attr $key=>$value 的數(shù)組 // $content 是 shortcode 中包含的字符串 // 對 $attr 和 $content 進行處理 // 返回預(yù)期的值} |
然后把自己定的 Shortcode 和其處理函數(shù)管理起來,以便 [mycode attr="value"]content[/mycode] 能夠按照預(yù)期執(zhí)行。
1 | add_shortcode('mycode', 'my_shortcode_func') |
WordPress 定義了以下和 Shortcode 相關(guān)的函數(shù):
1 2 3 4 | add_shortcode('mycode', 'function_name'); // 定義一個新的 Shortcoderemove_shortcode('mycode'); // 移除一個 Shortcoderemove_all_shortcodes(); // 移除所有的 Shortcode$return = do_shortcode($content); // 應(yīng)用 Shortcode 到內(nèi)容而不輸出 |
售前咨詢
售后咨詢
備案咨詢
二維碼
TOP