I'm working with a custom page template in Genesis and need to remove the post content and replace it when a certain condition is set. That part is working fine, but I also need to display information from a variable in the new content.
It seems simple, but something isn't working, and I think it's that I don't understand how to pass a variable into a function correctly. I'm assuming that a variable assigned outside of a function will be available in the function. Here's my template:
//* Template Name: Notification Template
$notice ="ALERT!"; //This will be set dynamically from code above, but I'll keep it simple for now.
if($notice){
//echo $notice ; // If I echo here, it displays at the top of the page.
remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
add_action ( 'genesis_entry_content', 'do_custom_content', 5 );
function do_custom_content(){
echo $notice; // This is not displaying anything!
echo 'Test Output'; //This text does display
}
}
When I echo the $notice in the do_custom_content() function, nothing is happening. So, it is probably that I don't understand how the php is working, since $notice is not passing through into the do_custom_content() function.