Weather Underground Plugin Expansion

My favorite Denver SEO company Katz Web Services announced the release of their latest awesome plugin- WP Wunderground Plugin.

It’s a well done, awesome plugin that allows you to use short codes to display the weather forecast in a widget or blog post.

For one of my clients however, we wanted the weather to be a part of the theme outside of a widget.

A small bit of code later, it’s done. You can see the weather forecast for Roanoke, VA by clicking that link.

We installed the WP Wunderground Plugin and then added this bit of code to our theme file:

if(class_exists(wp_wunderground)) :
	echo '<div id="rkr_weather">';
	$our_weather = new wp_wunderground;
	print $our_weather->build_forecast('24012');
	echo '</div>';

Now, an explanation of what you see.

Line 2 is a conditional statement checking to see if the plugin is currently active by checking to see if the plugin’s class exists. It wouldn’t exist if the plugin was active. You could also use the WordPress function is_plugin_active() but I’ve run into a couple of instances where it returns an unknown function error.

Lines 3 & 6 are simply creating a container «div» for styling purposes.

Lines 4 creates a new instance of the plugin class and Line 5 prints the result of the internal method build_forecast(). The ‘24012’ is the zip code I want the weather returned for and is also defined in the plugin settings.


Comments (5)

  1. Zack Katz - Reply
    October 5, 2010

    Thanks for the plugin plug :-)

    You could also use the shortcode to do this ( [forecast location="24012"] ). If you wanted to use it in your theme, you could use:

    echo '<div>'; do_shortcode('[forecast location="24012"]'); echo '</div>';

    • Marty Martin - Reply
      October 5, 2010

      This goes to show as much as you know about WordPress, there’s always something else to learn. I had forgotten about do_shortcode(), so, a hat tip to Zack!

  2. Chris - Reply
    June 13, 2011

    Hi there,

    Does anybody know how to use this code within your theme using custom fields? I have something of the following which of course doesn’t work, but you will get the idea of what I am attempting to do-

    • Chris - Reply
      June 13, 2011

      Hi, not all of my code posted correctly and not sure why. However if some is able to help I can email them the code to inspect.


      • Chris - Reply
        June 25, 2011

        Does anyone know how to achieve this?

Leave a Comment

    • Marty has been an active search marketing professional for over 12 years. He has consulted with the Fortune 100 and Fortune 500 as well as medium to small B2B and B2c businesses, governments and higher ed.