WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing a theme which has it's own set of database tables.
I'm wondering what is the best action for me to use when I want my install function to be invoked only once when the theme is activated for the first time?

I know there is a setup_theme action, but not sure if that's the one I should use.

share|improve this question
I think setup_theme is run on every page views. – julien_c Mar 6 '12 at 14:17
up vote 1 down vote accepted

You should read this: Activation/Deactivation hook for wordpress theme

share|improve this answer
Thanks, nice article. – Hamed Momeni Jan 29 '12 at 11:59
Lone link is considered a poor answer since it is meaningless by itself and target resource is not guaranteed to be alive in the future. Please try to include at least summary of information you are linking to. – Rarst Jan 29 '12 at 11:59

You could also try, since it's an SQL issue, using IF NOT EXISTS in your query to ensure that it doesn't run twice.

share|improve this answer
Thanks, I've already done that. – Hamed Momeni Jan 30 '12 at 8:58

Your Answer


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.