0

I'm coding a really simple plugin to add some slideshows to my theme. I also want to register a shortcode to invoke them from my pages. So far I have this:

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();

I omit the custom post type registration for brevity. The custom post type gets registered, but when I try to call the shortcode in a page with

[embed-slideshow]

nothing happens. I mean, I get [embed-slideshow] written. I've registered another shortcode from my theme functions and it works well.

Am I missing something really obvious? Any idea?

Thanks!

  • If I move the same functions to the the functions theme file, it works ok. So it must be something going on with the plugin creation. – Hector Lorenzo Feb 19 '14 at 7:51
  • Inside the plugins folder. The plugin has been activated, and as I said, the custom post type registration works. At first I thought it had something to do with the priority, but I don't know anymore... – Hector Lorenzo Feb 19 '14 at 8:06
0

Your shortcode action is wrong/incomplete:

function ss_register_shortcodes() {
    add_shortcode( 'embed-slideshow', array( $this, 'ss_shortcode_embed_slideshow' ) );
}

Since you are doing OOP, you have to use the class method in object context (or static).

  • 1
    To be honest, I've just started to code my custom plugins in an OOP fashion, and sometimes I completely forgot about those details. Thanks mate. – Hector Lorenzo Feb 19 '14 at 8:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.