WordPress.org

Ready to get started?Download WordPress

Forums

Weather Forecast - WP Wunderground
[resolved] PHP Widget and do_shortcode? (5 posts)

  1. Pete
    Member
    Posted 2 years ago #

    I'm using PHP Widget which allows PHP code to execute from a widget. I tried using this code to execute do_shortcode but it's not rendering

    <?php
    $lat = get_field('woo_maps_lat');
    $long = get_field('woo_maps_long');
    echo do_shortcode('[forecast location="' . $lat .','.$long. '" measurement=\'C\']');

    ?>
    If I echo a variable with simply `echo $lat;' it works. So the PHP Widget is working fine. The problem is echoing the shortcode in the widget. I can add shortcoded just fine to a widget but I need to be able to add the php variables where they are.

    I tried adding add_filter('widget_text', 'do_shortcode'); to my functions.php but it's still not rendering properly. Any suggestions?

    Thanks

    http://wordpress.org/extend/plugins/wunderground/

  2. Zack Katz
    Member
    Plugin Author

    Posted 2 years ago #

    Sorry, it looks good to me. Not sure what the problem might be.

  3. Pete
    Member
    Posted 2 years ago #

    Is there an pure PHP function I can use other than the shortcode [forcast]

  4. Pete
    Member
    Posted 2 years ago #

    I resolved this by removing all quotes from the do_shortcode code and the working code is below

    <div>
    <?php
    $lat = get_field('woo_maps_lat');
    $long = get_field('woo_maps_long');
    echo do_shortcode('[forecast location=' . $lat .','.$long. ']');
    ?>
    </div>
  5. Zack Katz
    Member
    Plugin Author

    Posted 2 years ago #

    Great, glad that worked. Thanks for posting the solution.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic