I have some setup code in my functions.php file that sets permalinks and adds categories that are used by the theme. I only want this code to run when the theme is first activated. There is no need for the code to run again. However, by placing it in the functions.php file, it runs each and every time a page on the website is loaded.
Is there an alternative method to use so that this code only runs when the custom theme is first activated?
In wp-includes/theme.php you’ll find the function
switch_theme(). It offers an action hook:So you may use this in your functions.php:
Just an idea; I haven’t tested it.