Title: Wrong theme on ajax request
Last modified: August 31, 2016

---

# Wrong theme on ajax request

 *  Resolved [lindesvard](https://wordpress.org/support/users/lindesvard/)
 * (@lindesvard)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/wrong-theme-on-ajax-request/)
 * Hi,
 * I have seen it’s possible to have different themes on ajax request. But I can’t
   get it to work. I in progress of doing a new design for my website and use your
   plugin to be able first release single.php. So I have two rules new:
 * **/posts/** – Use my new theme
    **?ajax=yes** – Use my new theme (this is for
   ajax requests)
 * Then I do a post request (/wp-admin/admin-ajax.php?ajax=yes) but it just returns
   0. And thats why it’s looks in the wrong theme. If I add my `add_action('wp_ajax_')`
   inside the old theme it works fine.
 * What am I doing wrong?
 * [https://wordpress.org/plugins/jonradio-multiple-themes/](https://wordpress.org/plugins/jonradio-multiple-themes/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Contributor [David Gewirtz](https://wordpress.org/support/users/dgewirtz/)
 * (@dgewirtz)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/wrong-theme-on-ajax-request/#post-6904733)
 * There are some real challenges about using Multiple Themes with Ajax requests.
   Even Jon (the author of the plugin) struggled with this. I’m guessing that perhaps
   you might need to rely on something other than the Ajax request to choose your
   theme (although I’m just guessing).
 * It is possible Multiple Themes can’t handle this, but it’s going to require a
   lot of experimenting.
 * Good luck!
 * –David
 *  [jon](https://wordpress.org/support/users/adiant/)
 * (@adiant)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/wrong-theme-on-ajax-request/#post-6904745)
 * I (the “Jon” that David mentions above) just took a look at the code and the 
   plugin’s AJAX-handling code is not being executed in any /wp-admin/ URLs because
   of a check of the is_admin() function.
 * My mind is a little foggy on what happened as I was fully occupied with two older
   relatives with huge medical issues. My best recollection is that the AJAX code
   was written and fully tested a long time earlier, then, much later, other issues
   came up that saw me have to rewrite the beginning of the plugin, and I more or
   less blindly coded the usual `if ( is_admin() )` logic that is used in almost
   all plugins.
 * When I decided to adopt out my plugins, I felt that I had to release the features
   I had been working on and thought I had completed. With so little time to spend
   on it, my testing was not comprehensive.
 *  Thread Starter [lindesvard](https://wordpress.org/support/users/lindesvard/)
 * (@lindesvard)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/wrong-theme-on-ajax-request/#post-6904761)
 * Hi David and Jon,
 * Thanks for the fast replies. My solution to this was the following. (This has
   nothing todo with my first post problem. That was just a examples of the problem.)
 * In my current situation I have some functionality in plugins instead of themes.
   And they do some DB things and then return a view. I don’t want this view in 
   my plugin anymore because I think it’s smarter to have view related things in
   my theme instead.
 * So when I do a ajax request to one of my plugins I will send a theme param that
   lets the plugin know what theme I’m currently on. Then I can load the correct
   template files in the new theme. But went I have loaded these views I can’t work
   with my themes new functions thats located in wp-content/themes/newtheme/app/
   bootstrap.php. So I do a require_once on that and now I have all functionality
   I need.
 * Hope you guys understood! This solved my issues atleast.
 *  Plugin Contributor [David Gewirtz](https://wordpress.org/support/users/dgewirtz/)
 * (@dgewirtz)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wrong-theme-on-ajax-request/#post-6905008)
 * Require_once can be a lifesaver. Glad it’s working for you (and thanks, Jon!).
 * –David
 * P.S. Marking as resolved because it is.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Wrong theme on ajax request’ is closed to new replies.

 * ![](https://ps.w.org/jonradio-multiple-themes/assets/icon-256x256.png?rev=1134086)
 * [Multiple Themes](https://wordpress.org/plugins/jonradio-multiple-themes/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/jonradio-multiple-themes/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/jonradio-multiple-themes/)
 * [Active Topics](https://wordpress.org/support/plugin/jonradio-multiple-themes/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/jonradio-multiple-themes/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/jonradio-multiple-themes/reviews/)

## Tags

 * [ajax](https://wordpress.org/support/topic-tag/ajax/)

 * 4 replies
 * 3 participants
 * Last reply from: [David Gewirtz](https://wordpress.org/support/users/dgewirtz/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/wrong-theme-on-ajax-request/#post-6905008)
 * Status: resolved