Support » Plugin: Theme Switcha » admin-ajax.php uses active theme instead of switched theme

  • Resolved scelen


    Hi there,

    First off, thanks for your plugin. As a theme developer it comes in very handy.

    Everything is working fine except for ajax calls. No matter what I try it always uses the current active theme instead of the one I’m previewing. The ajax call seems to have the cookie in the request headers though. Tried passing theme and passkey as $.ajax data but no luck.

    I’m on a multisite setup. One additional minor note is also that the plugin shows all installed themes. For multisite it would make sense to only list the themes that are assigned to the current site. Like I said, minor note.

    Thanks again

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Jeff Starr


    Thanks for the feedback.

    1) How/where is Ajax involved? In the theme settings? If you can elaborate a bit it will help.

    2) Multisite isn’t officially supported, but I will keep this in mind going forward.


    Thread Starter scelen


    Thanks for getting back to me so quickly.

    It’s a fairly basic setup with the function located in functions.php:

    add_action( 'wp_ajax_nopriv_load_makers', 'load_makers' );
    add_action( 'wp_ajax_load_makers', 'load_makers' );
    function load_makers(){
      echo '<span>foo</span>';

    and the javascript:

          type: 'POST',  
          url: ajaxurl,
          data: {action : 'load_makers'},
          cache: false,
          success: function() {...}

    It returns “0”, which is normal when the function is not found. If I add the function to the active theme’s functions file then it is found and it does work as expected. For other, normal requests it’s definitely using the functions file of the theme I’m previewing.


    Plugin Author Jeff Starr


    Thanks. May I ask what is wp_ajax_nopriv_load_makers? Haven’t heard of it before and not seeing anything in Google. I understand how WP Ajax works in general (I use it with some of my own plugins), but just not really understanding how it is being used in the issue described here.. are you using Ajax to load theme settings? Or some other aspect of the currently active theme? In other words, what exactly is not loading via Ajax when you are using a switched theme? Thanks.

    Updated to add: I remember now that wp_ajax_nopriv_{} is in fact a WP function, and that the load_makers part refers to the other function. Sorry for the confusion.

    • This reply was modified 4 years, 8 months ago by Jeff Starr.
    Thread Starter scelen


    It’s a custom function of mine. I’m using it to load a piece of HTML. Cheers

    Plugin Author Jeff Starr


    I will check to see if there is a way to modify targets of Ajax calls, but I’m not sure if it’s something supported by the WP API at this point. If you know otherwise, then please share. Thanks.

    Plugin Author Jeff Starr


    Gonna go ahead and mark this topic as resolved to keep things organized. Feel free to post again if needed. Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘admin-ajax.php uses active theme instead of switched theme’ is closed to new replies.