I have the following code in the functions.php file in my theme

  function my_func(){
    echo "foo";

I assume this function "my_func" will be called once in the admin_menu action; however I have found that the function is being called many times -it will print the word "foo" in the top of every widget of the dashboard-!! for me this is a strange behavior!,how can I make the function runs for one time? I want it to run when creating the admin menu?

Best Regards



It is executed only once. You see it multiple times because contents of those widgets are fetched via AJAX which loads WordPress in the ajax request again and hence it is echo'ed once again but it is executed only once per load. Makes sense?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.