国产欧美日韩第一页|日本一二三不卡视频|在线精品小视频,亚洲第一免费播放区,metcn人体亚洲一区,亚洲精品午夜视频

WordPress Shortcode的介紹

2016-06-24 07:45:47 12211

簡(jiǎn)單說(shuō) WordPress Shortcode 指的是一些使用[]包含的短代碼,WordPress會(huì)識(shí)別這些短代碼并根據(jù)短代碼的定義輸出為特定的內(nèi)容。

下面藍(lán)隊(duì)網(wǎng)絡(luò)為大家介紹一下它的類(lèi)型,基本概念,函數(shù),這三個(gè)方面

Shortcode 類(lèi)型

Shortcode API 支持幾乎所有可能的組合形式:自關(guān)閉標(biāo)簽,開(kāi)放標(biāo)簽,含有參數(shù)的標(biāo)簽等。

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]

Shortcode 基本概念

首先你要去定義一個(gè)函數(shù),來(lái)處理你定義的 Shortcode,和它的屬性參數(shù)以及引用的內(nèi)容。

1
2
3
4
5
6
function my_shortcode_func($attr, $content) {
    // $attr $key=>$value 的數(shù)組
    // $content 是 shortcode 中包含的字符串
    // 對(duì) $attr 和 $content 進(jìn)行處理
    // 返回預(yù)期的值}

然后把自己定的 Shortcode 和其處理函數(shù)管理起來(lái),以便 [mycode attr="value"]content[/mycode] 能夠按照預(yù)期執(zhí)行。

1
add_shortcode('mycode', 'my_shortcode_func')

Shortcode 相關(guān)的所有函數(shù)

WordPress 定義了以下和 Shortcode 相關(guān)的函數(shù):

1
2
3
4
add_shortcode('mycode', 'function_name'); // 定義一個(gè)新的 Shortcoderemove_shortcode('mycode'); // 移除一個(gè) Shortcoderemove_all_shortcodes(); // 移除所有的 Shortcode$return = do_shortcode($content); // 應(yīng)用 Shortcode 到內(nèi)容而不輸出


提交成功!非常感謝您的反饋,我們會(huì)繼續(xù)努力做到更好!

這條文檔是否有幫助解決問(wèn)題?

非常抱歉未能幫助到您。為了給您提供更好的服務(wù),我們很需要您進(jìn)一步的反饋信息:

在文檔使用中是否遇到以下問(wèn)題: