• Resolved lindesvard

    (@lindesvard)


    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/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor David Gewirtz

    (@dgewirtz)

    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

    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

    (@lindesvard)

    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

    (@dgewirtz)

    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.