Support » Plugin: PHP Code Widget » Shortcode not working

  • 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 which generates the shortcodes

    Any idea?

    Thanks again.

    http://wordpress.org/extend/plugins/php-code-widget/

Viewing 1 replies (of 1 total)
  • Plugin Author Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    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.