Nepo Znat
Nepo Znat

Reputation: 3270

WordPress Function on first Theme Activation

is there a way to execute a function only on the first activation of a specific theme?

I found this code but the problem is that the function will execute after every theme switch

<?php add_action("after_switch_theme", "mytheme_do_something"); ?>

Upvotes: 0

Views: 93

Answers (1)

Ron van der Heijden
Ron van der Heijden

Reputation: 15080

Yes you can by writing and checking an option.

add_action("after_switch_theme", "mytheme_do_something");
function mytheme_do_something() {
     if( ! get_option( 'mytheme_setting' ) ) {
         add_option( 'mytheme_setting', '1');
         // some things you want to do
     }
}

Upvotes: 1

Related Questions