running a function on theme activation in functions.php (3 posts)

  1. legend411
    Posted 6 years ago #

    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?

  2. legend411
    Posted 6 years ago #

    well, i supposed I could do


    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?

  3. wesg
    Posted 5 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.