I have posted this question: How to use shortcodes on a widget sidebar when doing an ajax call?, with no answers. Now I want to ask a more specific question.
The problem seems to be that the shortcode is not processed by the plugin., as if I replace the shortcode with e.g. [audio src="audioFile.ogg"]
it works perfect.
So I'm guessing that I could make it work if the plugin is loaded before. But I don't know how to achieve it (maybe I'm wrong with it).
Any suggestion?
This is the code in functions.php
:
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
apply_filters('ps_register_shortcode_ajax', 'slider_widget_init');
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"]' );
get_template_part( 'home', 'ajax' );
die();
}
The Slider side-bar is loaded just in home and-home-ajax pages (id=8). It works right in home page, but not in home-ajax page.