0

I'm trying to use a shortcode from Promotion Slider Plugin inside a widget when doing an ajax call. As said here, I could achieve it doing:

add_action( 'init', function() { 
  ps_register_shortcode_ajax( 'ps_get_slider', '8' ); 
} );

function ps_register_shortcode_ajax( $callable, $action ) {
if(isset($_POST['href'])) {
      $pageId = preg_match( '/^http:\/\/.+\/\?page_id=\d+$/', $_POST['href'] ) ? substr( strrchr( $_POST['href'], '=' ), 1 ) : '8' ;

      if ( empty( $pageId ) || $pageId != $action )
        return;

      call_user_func( $callable );
}
}

function ps_get_slider() {
    //require_once('../wp-load.php'); Nothing changes
    if ( dynamic_sidebar('Slider') ) : else : endif;
    //echo do_shortcode( '[promoslider post_type="news" height="300px" width="70%" numberposts="5" start_on="first" display_title="fancy" display_excerpt="excerpt"  pause_on_hover="pause"]' );  Same output than above
    die(); 
} 

but I'm just getting the literal output: [promoslider post_type="news" height="300px" width="70%" numberposts="5" start_on="first" display_title="fancy" display_excerpt="excerpt" pause_on_hover="pause"].

Any idea of how could achieve it?

As a note, I first tried just adding if ( dynamic_sidebar('Slider') ) : else : endif; into the ajax template, but didn't work.

  • You may need the widget_text filter to resolve shortcodes in widgets as this doesn't happen by default, see digwp.com/2010/03/shortcodes-in-widgets for a reference. – Mario Peshev Jan 9 '14 at 14:32
  • @MarioPeshev - The shortcode works right if it's not an Ajax call. I had tried your suggestion adding this filter at the start of ps_get_slider() function without success (same output). – Manolo Jan 9 '14 at 14:38

Your Answer

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

Browse other questions tagged or ask your own question.