WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

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 )

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

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.

share|improve this question

marked as duplicate by kaiser Feb 18 '14 at 2:40

This question was marked as an exact duplicate of an existing question.

Post your code please. – s_ha_dum Jan 9 '14 at 14:29
@s_ha_dum - Done – Manolo Jan 9 '14 at 14:43
There is too much going on there for me to be be able to replicate the problem in any reasonable time. Please reduce that to a bare minimum sample case that demonstrates the problem. Sorry, but I need to paste that into a dev-stack and run the code. I don't have time to reverse engineer it. Also, this is the same question as your other one even if worded slightly differently. I'd delete one or the other. – s_ha_dum Jan 9 '14 at 14:53
@s_ha_dum - All right. Now it is the most relevant code. – Manolo Jan 9 '14 at 15:28
@s_ha_dum - I'd prefer to delete one question when the problem is resolved. – Manolo Jan 9 '14 at 15:29

You are not using ajax right. Why are you adding your ajax callback function to the init action? You need to read http://codex.wordpress.org/AJAX_in_Plugins

Attach your ajax callback function to wp_ajax_your_defined_action like this:

add_action( 'wp_ajax_your_defined_action', 'your_callbck_function' );

For this to work you have to use wp-admin/admin-ajax.php as your ajax url and you have to post your_defined_action to action.

                type: 'POST',
                url: ajaxurl, //This is defined only on admin side
                data: {
                    action: 'your_defined_action',
                    some_var: 'Some Var Content'
                success: function (response) {
share|improve this answer
Yes, I deleted this part of the code because I think it is right. You can check at wordpress.stackexchange.com/questions/128971/… – Manolo Jan 9 '14 at 18:55

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