WordPress.org

Ready to get started?Download WordPress

Forums

PHP Code Widget
Is there a way to use shortcode? (4 posts)

  1. crsneilhedley
    Member
    Posted 1 year ago #

    Trying to use shortcode from the WordPress-Amazon-Associate plugin. It generates the following for an album we reviewed:

    [amazon_enhanced asin="B00723NWJE" container="" container_class="" larger_image="false" price="New" background_color="FFFFFF" link_color="000000" text_color="0000FF" /]

    If I put that in a sidebar TEXT/HTML widget, it displays properly. If I put it in the PHP/TEXT/HTML widget, it simply shows the shortcode.

    I want to use the PHP widget so I generate the ASIN part of the shortcode dynamically. Is it possible?

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

  2. Skalders
    Member
    Posted 1 year ago #

    I'd like to know this too. shorthand & php are both necessary for me.

  3. Skalders
    Member
    Posted 1 year ago #

    If anyone still wants to know, I have a solution.
    Instead of using this plugin, i made the default text widget support php code.

    All you have to do is add this in your functions.php file:

    add_filter('widget_text', 'php_text', 99);
    
    function php_text($text) {
     if (strpos($text, '<' . '?') !== false) {
     ob_start();
     eval('?' . '>' . $text);
     $text = ob_get_contents();
     ob_end_clean();
     }
     return $text;
    }
  4. robbieeeee
    Member
    Posted 1 year ago #

    Nice one Skalders :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.