无法识别从插件注册的快捷代码

时间:2014-02-19 作者:Hector Lorenzo

我正在编写一个非常简单的插件,为我的主题添加一些幻灯片。我还想注册一个短代码,从我的页面中调用它们。到目前为止,我有:

class Slideshow {

public function __construct() {

    // Register the project custom post type
    add_action( \'init\', array( $this, \'ss_register_slideshow_type\' ), 0 );
    add_action( \'init\', array( $this, \'ss_register_shortcodes\' ), 0 );
}

function ss_register_slideshow_type() {}

function ss_register_shortcodes() {
    add_shortcode( \'embed-slideshow\', \'ss_shortcode_embed_slideshow\' );
}

function ss_shortcode_embed_slideshow( $atts ) {
    return \'Foo\';
}

}

// init
$slideshow_instance = new Slideshow();
为了简洁起见,我省略了自定义的post类型注册。自定义post类型已注册,但当我尝试在具有

[embed-slideshow]
什么都没发生。我的意思是,我写了[嵌入幻灯片]。我已经从我的主题函数中注册了另一个短代码,它运行得很好。

我是否错过了一些非常明显的东西?有什么想法吗?

谢谢

1 个回复
最合适的回答,由SO网友:tfrommen 整理而成

您的快捷码操作错误/不完整:

function ss_register_shortcodes() {
    add_shortcode( \'embed-slideshow\', array( $this, \'ss_shortcode_embed_slideshow\' ) );
}
由于您正在执行OOP,因此必须在对象上下文(或静态)中使用class方法。

结束

相关推荐

Youtube shortcode

我正在努力使这个短代码起作用,但没有任何成功。所有的尝试都给了我一个白色的方块。 function youtube($atts) { extract(shortcode_atts(array( \"value\" => \'https://www.youtube.com/watch?v=EhWopzlRwZ8\', \"width\" => \'475\', \"height\" => \'350\', \