2015-06-05 21 views
0

有沒有辦法執行一個功能只有在第一次激活特定的主題?第一次主題激活WordPress的功能

我發現這個代碼,但問題是,該函數將每一個主題後,再執行切換

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

回答

1

是的,你可以通過編寫和檢查的選項。

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 
    } 
} 
+0

非常感謝。我認爲這會更復雜:) – sascha