Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
WP - pass variable into wp_footer and other actions hooks and filters
// Pass a value to a hook in an annonymous 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