Title: running a function on theme activation in functions.php
Last modified: August 19, 2016

---

# running a function on theme activation in functions.php

 *  [legend411](https://wordpress.org/support/users/legend411/)
 * (@legend411)
 * [17 years ago](https://wordpress.org/support/topic/running-a-function-on-theme-activation-in-functionsphp/)
 * I’ve made plugins before that ran a function on plugin activation, by hooking
   into the activate action, like this:
 * `add_action('activate_plugin-name.php', 'function-name');`
 * but I was wondering if there was a action I could hook into to run a function
   in the functions.php file of a theme, to run that function when the theme is 
   activated (specifically, to build a table in the database).
 * Can anyone help?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [legend411](https://wordpress.org/support/users/legend411/)
 * (@legend411)
 * [17 years ago](https://wordpress.org/support/topic/running-a-function-on-theme-activation-in-functionsphp/#post-1092333)
 * well, i supposed I could do
 * `add_action('wp_head','function-name')`
 * Given my purpose (creating a table in the db) it will work so long as i do IF
   NOT EXISTS in my sql statement in the function… but its still going to be running
   the query every time a page loads, I imagine thats pretty poor practice.
 * Anyone have suggestions?
 *  [wesg](https://wordpress.org/support/users/wesg/)
 * (@wesg)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/running-a-function-on-theme-activation-in-functionsphp/#post-1092518)
 * I know this post is very old, but I was looking for a similar thing. It seems
   that the hook `register_activation_hook( __FILE__, 'function');` does not work
   for themes. Is there an alternative?

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘running a function on theme activation in functions.php’ is closed to
new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [wesg](https://wordpress.org/support/users/wesg/)
 * Last activity: [16 years, 1 month ago](https://wordpress.org/support/topic/running-a-function-on-theme-activation-in-functionsphp/#post-1092518)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
