Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

  function my_func(){
    echo "foo";
  }         
  add_action('admin_menu','my_func');

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

Thanks

share|improve this question

1 Answer 1

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?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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