Title: shortcode in functions.php
Last modified: August 30, 2016

---

# shortcode in functions.php

 *  Resolved [internetimage](https://wordpress.org/support/users/internetimage/)
 * (@internetimage)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/shortcode-in-functionsphp-1/)
 * Hello,
 * I try to run in functions.php a tablepress shortcode.
    The shortcode don’t execute
   and return the string name. An example:
 *     ```
       function process_post() {
             echo do_shortcode("[table id=1 /]");
       }
       add_action("init", "process_post");
       ```
   
 * I checked if the plugin is enable and loaded. Can you help me?
 * Thanks.
 * [https://wordpress.org/plugins/tablepress/](https://wordpress.org/plugins/tablepress/)

Viewing 15 replies - 1 through 15 (of 18 total)

1 [2](https://wordpress.org/support/topic/shortcode-in-functionsphp-1/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/shortcode-in-functionsphp-1/page/2/?output_format=md)

 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/shortcode-in-functionsphp-1/#post-6647797)
 * Hi,
 * thanks for your post, and sorry for the trouble.
 * I’m afraid that your code won’t work like this. You are basically already printing
   the Shortcode output on the `init` hook, which is too early, as it hasn’t been
   registered then, yet.
 * Can you maybe elaborate what you are trying to achieve, so that I can make suggestions?
 * Regards,
    Tobias
 *  Thread Starter [internetimage](https://wordpress.org/support/users/internetimage/)
 * (@internetimage)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/shortcode-in-functionsphp-1/#post-6647853)
 * Thanks for reply.
    I try to print the table in a pdf. When I click “print” I 
   process some parameter in the post variable and print the page with the mpdf 
   library.
 * Regards
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/shortcode-in-functionsphp-1/#post-6647854)
 * Hi,
 * but then the Shortcode should already be in the page?!
 * I assume that the problem (with the default post/page content) also is that the
   Shortcode is printed instead of the table? Is the POST request going to the admin
   area or to the frontend?
 * Regards,
    Tobias
 *  Thread Starter [internetimage](https://wordpress.org/support/users/internetimage/)
 * (@internetimage)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/shortcode-in-functionsphp-1/#post-6647988)
 * Hi,
 * I print shortcode in a frontend.
    Regards
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/shortcode-in-functionsphp-1/#post-6647989)
 * Hi,
 * then, just use the Shortcode in the post/page content or the TablePress Template
   Tags in PHP. That’s the best solution for this.
 * Regards,
    Tobias
 *  Thread Starter [internetimage](https://wordpress.org/support/users/internetimage/)
 * (@internetimage)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/shortcode-in-functionsphp-1/#post-6647990)
 * I did not understand.
 * I use the shortcode in template but i render all in the pdf insted in html page.
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/shortcode-in-functionsphp-1/#post-6647991)
 * Hi,
 * the question is how that PDF saving works, i.e. when its request executes, and
   in which context. What is the URL for the save request?
 * Regards,
    Tobias
 *  Thread Starter [internetimage](https://wordpress.org/support/users/internetimage/)
 * (@internetimage)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/shortcode-in-functionsphp-1/#post-6647993)
 * I think, the problem is that I process $_POST in the init hook and I use the 
   shortcode. The hook init is too early. What is the good hook for the shortcode?
 *  Thread Starter [internetimage](https://wordpress.org/support/users/internetimage/)
 * (@internetimage)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/shortcode-in-functionsphp-1/#post-6647996)
 * I simplify the code for you:
 *     ```
       add_action('init', 'process_post', 21);
       function process_post() {
        if (isset($_GET['output']) && $_GET['output'] == 'pdf') {
   
               if (shortcode_exists('table')) {
                   echo "EXIST";
               } else {
                   echo "NOT EXIST";
               }
               echo do_shortcode('[table id=1 /]');
               exit();
       }
       }
       ```
   
 * The result is : NOT EXIST [table id=1 /]
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/shortcode-in-functionsphp-1/#post-6647997)
 * Hi,
 * ok, and what is the URL that you are calling to see this output?
 * Regards,
    Tobias
 *  Thread Starter [internetimage](https://wordpress.org/support/users/internetimage/)
 * (@internetimage)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/shortcode-in-functionsphp-1/#post-6647998)
 * Hi,
 * I resolve the problem with the function `tablepress_print_table(array('id' =>
   $flip[$post_obj->ID]));`
 * Thanks!
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/shortcode-in-functionsphp-1/#post-6647999)
 * Hi,
 * very nice! Yes, that’s what I meant. The Template Tag Functions are the proper
   way to go here.
 * Best wishes,
    Tobias
 *  [bsieders](https://wordpress.org/support/users/bsieders/)
 * (@bsieders)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/shortcode-in-functionsphp-1/#post-6648063)
 * Hi Tobias!
 * Similar but different problem:
 * I’ve added a function that sends an email to all subscribers when a new post 
   has been published but it does not parse the tablepress shortcodes when I try
   to use the following:
 *     ```
       add_action('publish_post', 'notify_subscribers_new_post');
       function notify_subscribers_new_post() {
       //email code...
       $emailcontent = do_shortcode(apply_filters('the_content', $post->post_content, false));
       }
       ```
   
 * I’m guessing do_shortcode is being called before the plugin knows what to do 
   with it? Anyway around this?
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/shortcode-in-functionsphp-1/#post-6648064)
 * Hi,
 * you are correct, TablePress does not load its Shortcodes in the admin area (where
   your code is run).
    To work around that, please try using the code from the post
   [https://wordpress.org/support/topic/tablepress-apple-news?replies=16#post-8277314](https://wordpress.org/support/topic/tablepress-apple-news?replies=16#post-8277314)
 * Regards,
    Tobias
 *  [bsieders](https://wordpress.org/support/users/bsieders/)
 * (@bsieders)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/shortcode-in-functionsphp-1/#post-6648065)
 * Awesome that worked! 🙂
 * I will donate something on your wordpress plugin page in return for spreading
   the coding love.
 * Regards from Rotterdam,
 * Balthazar

Viewing 15 replies - 1 through 15 (of 18 total)

1 [2](https://wordpress.org/support/topic/shortcode-in-functionsphp-1/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/shortcode-in-functionsphp-1/page/2/?output_format=md)

The topic ‘shortcode in functions.php’ 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/)

 * 18 replies
 * 3 participants
 * Last reply from: [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * Last activity: [9 years, 11 months ago](https://wordpress.org/support/topic/shortcode-in-functionsphp-1/page/2/#post-6648068)
 * Status: resolved