WordPress.org

Support

Support » How-To and Troubleshooting » running a function on theme activation in functions.php

running a function on theme activation in functions.php

  • legend411
    Member

    @legend411

    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)
  • legend411
    Member

    @legend411

    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?

    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.