什么是wordpress中的[(特殊功能)],以及我如何为我的插件启用它们


What are the [(special function)] in wordpress, and how do I enable them for my plugin?

我想在WordPress页面中包含一个函数,但是因为WordPress不允许使用<?php ?>标签,所以我不能定期添加函数。

我注意到当使用一个画廊插件时,它添加了[flagallery gid=1 name="Gallery"]到页面内容(在视觉模式下编辑页面时)。有没有办法在我的插件中设置这个?

就像在我的页面上有[myPlugin category=myCategory]运行:

function myPlugin($category) {
    echo ...
}

它们被称为短代码

这个链接应该告诉你开始使用它们所需要知道的一切:http://codex.wordpress.org/Shortcode_API

伪的例子:

function category( $cat ) {
    extract( shortcode_atts( array(
        'cat' => 'something'
    ), $atts ) );
    return "category is {$cat}";
}
add_shortcode( 'myPlugin', 'category' );