Title: Shortcode not working
Last modified: August 20, 2016

---

# Shortcode not working

 *  [jncnath](https://wordpress.org/support/users/jncnath/)
 * (@jncnath)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/shortcode-not-working-9/)
 * Hi Otto,
 * The plugin works great but I’m having an issue with getting shortcode to be processed
   properly in the widget. Here is what I did:
 * 1. Added filters to my active theme function.php file
 *     ```
       // Allow shortcodes in text widgets
       		add_filter('widget_text', 'shortcode_unautop');
       		add_filter('widget_text', 'do_shortcode');
   
       		// Allow shortcodes in php code widget
       		add_filter('widget_execphp', 'shortcode_unautop');
       		add_filter('widget_execphp', 'do_shortcode');
       ```
   
 * 2. Added the following to the php widget
 *     ```
       <?php
       $id = get_the_ID();
       $amazon_product_asin_value = get_post_meta($id, 'amazon_product_asin', true);
         echo do_shortcode('<div> [amazon asin=' . $amazon_product_asin_value . '&template=buynowamazon_widget&chan=default] </div>');
       ?>
       ```
   
 * I also tried without do_shortcode and same result.
 * #2 properly outputs the shortcode of [amazon asin=B008I20FT8&template=buynowamazon_widget&
   chan=default] which works fine if I just enter this in the standard text widget
 * I’m using the [Amazon Link plugin](http://wordpress.org/extend/plugins/amazon-link/)
   which generates the shortcodes
 * Any idea?
 * Thanks again.
 * [http://wordpress.org/extend/plugins/php-code-widget/](http://wordpress.org/extend/plugins/php-code-widget/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [13 years, 5 months ago](https://wordpress.org/support/topic/shortcode-not-working-9/#post-3281357)
 * The plugin doesn’t support shortcodes. I have no idea how to make them work in
   it.
 * However, the widget_execphp filter is applied *before* the PHP is executed. So
   using PHP that creates a shortcode definitely won’t work. Instead of creating
   a shortcode, just make your PHP create the HTML you want instead.
 * I mean, what you’re trying to do is kind of backwards. You’re writing PHP to 
   create a shortcode which will then be processed by other PHP to turn into HTML…
   Just skip the middleman.

Viewing 1 replies (of 1 total)

The topic ‘Shortcode not working’ is closed to new replies.

 * ![](https://ps.w.org/php-code-widget/assets/icon.svg?rev=992095)
 * [PHP Code Widget](https://wordpress.org/plugins/php-code-widget/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/php-code-widget/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/php-code-widget/)
 * [Active Topics](https://wordpress.org/support/plugin/php-code-widget/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/php-code-widget/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/php-code-widget/reviews/)

## Tags

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

 * 1 reply
 * 2 participants
 * Last reply from: [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/shortcode-not-working-9/#post-3281357)
 * Status: not resolved