Reputation: 3270
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
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