Title: Run shortcode inside AJAX request
Last modified: August 21, 2016

---

# Run shortcode inside AJAX request

 *  Resolved [surfweb82](https://wordpress.org/support/users/surfweb82/)
 * (@surfweb82)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/run-shortcode-inside-ajax-request/)
 * I’m using this plugin and it is really useful!
 * If I load a page normally the shortcode is interpreted as if I load the page 
   with an ajax request not display anything.
 * How can I fix the problem?
 * Thanks in advance
 * [https://wordpress.org/plugins/tablepress/](https://wordpress.org/plugins/tablepress/)

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

 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/run-shortcode-inside-ajax-request/#post-4993306)
 * Hi,
 * thanks for your post, and sorry for the trouble.
 * The reason for this most likely is that TablePress only registers the Shortcode
   on the frontend (i.e. when `is_admin()` is `false` in the code). The AJAX request
   probably goes through `admin-ajax.php`, so that the Shortcode is not registered.
   
   To change that, please try adding this to the “functions.php” of your theme:
 *     ```
       add_action( 'init', 'load_tablepress_in_the_admin', 11 ) );
       function load_tablepress_in_the_admin() {
         if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ) {
           TablePress::$controller = TablePress::load_controller( 'admin_ajax' );
         }
       }
       ```
   
 * Regards,
    Tobias
 *  Thread Starter [surfweb82](https://wordpress.org/support/users/surfweb82/)
 * (@surfweb82)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/run-shortcode-inside-ajax-request/#post-4993319)
 * Hi Tobias.
 * Thanks for your quick response.
 * I added the function you gave me but unfortunately the ajax request returns the
   shortcode: [table id=1 /]
 * I have tried different solutions but unfortunately I did not get any results.
 * Any idea?
 * Thank you again for your reply!
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/run-shortcode-inside-ajax-request/#post-4993323)
 * Hi,
 * ok, that’s strange.
    Have you tried other Shortcodes, to find out if this is 
   maybe some other problem? For example, it might be possible that the AJAX request
   is simply not evaluating Shortcodes because they are not run through `do_shortcodes()`(
   which is usually tied to the `the_content` filter that is evaluated during a 
   regular page view). This is likely the case if the AJAX request simply returns`
   $post->post_content` from the database.
 * Regards,
    Tobias
 *  Thread Starter [surfweb82](https://wordpress.org/support/users/surfweb82/)
 * (@surfweb82)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/run-shortcode-inside-ajax-request/#post-4993331)
 * Yes, I have tried other shortcodes. If the shortcodes are included in the theme
   are interpreted.
 * I tried to install other plugins and inserting the shortcode get the same result
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/run-shortcode-inside-ajax-request/#post-4993339)
 * Hi,
 * with “get the same result”, you mean that the Shortcode is not interpreted, but
   shown as plain text?
    Then, this is likely an issue in the theme, and you might
   want to contact the theme developers.
 * Regards,
    Tobias
 *  Thread Starter [surfweb82](https://wordpress.org/support/users/surfweb82/)
 * (@surfweb82)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/run-shortcode-inside-ajax-request/#post-4993343)
 * Hi.
 * Only plugins’s shortcodes are displayed as text. The shortcodes’s theme are interpreted
   correctly.
 * The theme I’m using is the wordpress default theme
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/run-shortcode-inside-ajax-request/#post-4993408)
 * Hi,
 * ok, and how is that AJAX request working then? Are you using a plugin for that?
 * Regards,
    Tobias
 *  Thread Starter [surfweb82](https://wordpress.org/support/users/surfweb82/)
 * (@surfweb82)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/run-shortcode-inside-ajax-request/#post-4993417)
 * Hi.
 * Thanks for your patience!
 * I installed a fresh copy of wordpress. I’m using twentyfourteen theme.
 * This is the code entered in the functions.php file: [http://pastebin.com/w7BBgS32](http://pastebin.com/w7BBgS32)
 * In the functions.php file I added a simple shortcode.
 * This is the javascript code: [http://pastebin.com/xSnupVCZ](http://pastebin.com/xSnupVCZ)
 * I’ve installed tablepress plugin. I created a test table
 * I created a test page. I entered my shortcode and shortcode generated by plugin
 * When I load page my shortcode is interpreted but the plugin’s shortcode no.
 * Need more details?
 * Thanks
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/run-shortcode-inside-ajax-request/#post-4993425)
 * Hi,
 * ah, I just noted a mistake in my code… Sorry.
    Please try replacing
 *     ```
       TablePress::$controller = TablePress::load_controller( 'admin_ajax' );
       ```
   
 * with
 *     ```
       TablePress::load_controller( 'frontend' );
       ```
   
 * exactly like that.
 * Regards,
    Tobias
 *  Thread Starter [surfweb82](https://wordpress.org/support/users/surfweb82/)
 * (@surfweb82)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/run-shortcode-inside-ajax-request/#post-4993427)
 * Thank you! Now it works!
 * There is still one small thing: your plugin load javascript in the footer. With
   ajax javascript are not loaded.
 * Is there a way to load javascript with the ajax requests?
 * Thank you very much! You are great!
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/run-shortcode-inside-ajax-request/#post-4993428)
 * Hi,
 * great to hear that this works! 🙂
 * And the JavaScript is indeed a problem here, but I don’t really see a solution
   for that. Injecting JavaScript as the result of an AJAX call is tricky (because
   of security issues that are implied), and I don’t know a standard solution here,
   sorry.
 * Regards,
    Tobias
 *  Thread Starter [surfweb82](https://wordpress.org/support/users/surfweb82/)
 * (@surfweb82)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/run-shortcode-inside-ajax-request/#post-4993429)
 * Thanks for your help!
 * For javascript I’ll try to find a solution.
 * Have a nice day
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/run-shortcode-inside-ajax-request/#post-4993431)
 * Hi,
 * no problem, you are very welcome! 🙂 Always glad when I can help!
 * Best wishes,
    Tobias
 * P.S.: In case you haven’t, please [rate TablePress](http://wordpress.org/support/view/plugin-reviews/tablepress)
   here in the plugin directory. Thanks!

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

The topic ‘Run shortcode inside AJAX request’ is closed to new replies.

 * ![](https://ps.w.org/tablepress/assets/icon.svg?rev=3192944)
 * [TablePress - Tables in WordPress made easy](https://wordpress.org/plugins/tablepress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/tablepress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/tablepress/)
 * [Active Topics](https://wordpress.org/support/plugin/tablepress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/tablepress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/tablepress/reviews/)

## Tags

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

 * 13 replies
 * 2 participants
 * Last reply from: [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * Last activity: [11 years, 11 months ago](https://wordpress.org/support/topic/run-shortcode-inside-ajax-request/#post-4993431)
 * Status: resolved