Skip to content

Instantly share code, notes, and snippets.

@tripflex
Last active September 30, 2017 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripflex/bcf0fe93acec9034df75dbc77e652baa to your computer and use it in GitHub Desktop.
Save tripflex/bcf0fe93acec9034df75dbc77e652baa to your computer and use it in GitHub Desktop.
Custom WordPress simple-weather shortcode to generate simple-weather shortcode from custom values
<?php
// Add Shortcode
function my_weather_listing_feed_handler( $atts ) {
// If not using default job location field, change to appropriate meta key below
// !!! IF USING A WP JOB MANAGER FIELD IT MUST BE PREPENDED WITH AN UNDERSCORE !!!
$meta_key = '_job_location';
// Attributes (value set here is default, and will be overwritten if supplied in shortcode arguments)
$atts = shortcode_atts(
array(
'night' => 'yes',
'days' => '5',
'text_align' => 'center',
'units' => 'metric',
'style' => 'large-icons',
'api' => 'XXXXXXXXXXX',
'location' => sanitize_text_field( get_post_meta( get_the_ID(), $meta_key, true ) ),
),
$atts
);
// As long as there is a location, let's generate the shortcode to use
if( ! empty( $atts['location'] ) ){
$gen_shortcode = "[simple-weather night=\"{$atts['night']}\" days=\"{$atts['days']}\" text_align=\"{$atts['text_align']}\" units=\"{$atts['units']}\" style=\"{$atts['style']}\" api=\"{$atts['api']}\" location=\"{$atts['location']}\"]";
$return_data = do_shortcode( $gen_shortcode );
} else {
$return_data = '';
}
return $return_data;
}
add_shortcode( 'weather_listing_feed', 'my_weather_listing_feed_handler' );
@tripflex
Copy link
Author

This is for the Simple Weather widget on CodeCanyon (not the free one on WordPress repo):
https://codecanyon.net/item/weather-simple-wordpress-shortcode-widget/5458355?ref=tripflex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment