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)

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.