Title: Get shortcode of form programmatically, using form&#8217;s ID
Last modified: September 11, 2024

---

# Get shortcode of form programmatically, using form’s ID

 *  Resolved [nimmolo](https://wordpress.org/support/users/nimmolo/)
 * (@nimmolo)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/get-shortcode-of-form-programmatically-using-forms-id/)
 * I’d like to use a contact form in a general template like `single.php`, but I’d
   like to be able to configure which form is included in the template as a site
   option. The shortcode should not appear in the `post_content`, it should be coded
   into the template.
 * But instead of a hardcoded form value like `[contact-form-7 id="e07e78b" title
   ="Inquire about this work"]`, I’d like to be able to configure which form appears.
 * Using ACF, I can store a specific `contact_form` as a site `option`. ( `contact_form`
   is a post_type, so i can pick which form I want to store in the option, and access
   it elsewhere via `get_field` .)
 * I’m trying to understand if there’s a way to use that form’s ID to get the **
   generated shortcode** for that form. I notice that the form shortcode `id` does
   not correspond to the form’s `post_id` in the database, and I can’t find where
   it’s stored in the `post_meta` of the form, either.
 * I do find that there’s a method of `WPCF7_ContactForm` called `shortcode()` that
   generates the shortcode. I’m wondering how I can pass the form `$post` object
   and get the generated shortcode for it, in a template.

Viewing 1 replies (of 1 total)

 *  Thread Starter [nimmolo](https://wordpress.org/support/users/nimmolo/)
 * (@nimmolo)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/get-shortcode-of-form-programmatically-using-forms-id/#post-18009268)
 * This worked. Thanks for the plugin!
 * My ACF `options` field `inquiry_form` is set up to return the full `$post` instance,
   but you can just return the `ID` and modify a bit below.
 *     ```wp-block-code
       if ($contact_form = get_field('inquiry_form', 'options')) {   // this is what gets the instance of the form with the shortcode() method   $full_form = WPCF7_ContactForm::get_instance($contact_form->ID)   // note that the instance, not the post, has the method available.   $shortcode = esc_attr($full_form->shortcode());   // you need to translate the html entities back to text   echo apply_shortcodes( html_entity_decode($shortcode) );}
       ```
   
    -  This reply was modified 1 year, 8 months ago by [nimmolo](https://wordpress.org/support/users/nimmolo/).
    -  This reply was modified 1 year, 8 months ago by [nimmolo](https://wordpress.org/support/users/nimmolo/).

Viewing 1 replies (of 1 total)

The topic ‘Get shortcode of form programmatically, using form’s ID’ is closed to
new replies.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

## Tags

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

 * 1 reply
 * 1 participant
 * Last reply from: [nimmolo](https://wordpress.org/support/users/nimmolo/)
 * Last activity: [1 year, 8 months ago](https://wordpress.org/support/topic/get-shortcode-of-form-programmatically-using-forms-id/#post-18009268)
 * Status: resolved