Title: Execute shortcode in response to a button
Last modified: September 1, 2016

---

# Execute shortcode in response to a button

 *  [NorthernLights1](https://wordpress.org/support/users/northernlights1/)
 * (@northernlights1)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/execute-shortcode-in-response-to-a-button/)
 * So I have this Optin Form plugin that gives me a [optinform] shortcode. How can
   I make the optin form appear as a response to a widget button being clicked on
   screen?
 * Basically I want to work like this:
    Click “sign up” button (button created by
   widget plugin) >>> Optin Form popup appears

Viewing 1 replies (of 1 total)

 *  [epicdevspace](https://wordpress.org/support/users/epicdevspace/)
 * (@epicdevspace)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/execute-shortcode-in-response-to-a-button/#post-7541259)
 * Hi
 * In your child theme’s header.php
 *     ```
       <script>
       function execute_mcode() {
          var url="<?php echo get_template_directory_uri(); ?>/yourshortcode.php";
          jQuery.post(url,function(data){
          console.log(data);
          });
       }
       </script>
       ```
   
 * In your yourshortcode.php:
    `<?php echo do_shortcode('[optinform]'); ?>`
 * and use the following in your button:
 *  `onclick="execute_mcode()"`
 * All the best!

Viewing 1 replies (of 1 total)

The topic ‘Execute shortcode in response to a button’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [epicdevspace](https://wordpress.org/support/users/epicdevspace/)
 * Last activity: [9 years, 10 months ago](https://wordpress.org/support/topic/execute-shortcode-in-response-to-a-button/#post-7541259)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
