You will need to declare the variable global
before using it.
function simple_form(){
global $firstname;
$firstname="Bob";
//Do something to populate the form field name <fname> with "Bob"
}
Your form should be able to do …
global $firstname;
echo $firstname;
… to use the variable.
However, I can’t help but think there is a better way to do this.
- Setting a
global
is best avoided if you can - and doing what you are doing– hooking to
wp
— you are going to populate these variable for every page on the site– both front and back end– every time a page loads. That is a waste of resources. There are many, many other hooks and I am pretty sure that one of them would work much better thanwp
.
Without having more details about your project I don’t think I can do better than generalities but edit your question and I will edit my answer.