Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WP - pass variable into wp_footer and other actions hooks and filters
<?php
// Pass a value to a hook in an annonymous function
add_shortcode('show_weather',function(){
$a = shortcode_atts( array(
'location' => 'Vancouver, BC',
), $atts, 'show_weather' );
$city = $a['location'];
// somthing for the placeholder
$return = "<div id='weather'><span>{$city}</span></div>";
// resources required, but in footer
// that require shortcode attribute `location`
add_action('wp_footer', function() use ($city) { // 🎉
//echo "<script> ... location: {$city}; ... </script>";
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.