I am trying to setup image sizes on theme activation using the hook after_setup_theme
but it dosent seems like it is never really called. Why?
if( !function_exists('theme_image_size_setup') )
{
function theme_image_size_setup()
{
//Setting thumbnail size
update_option('thumbnail_size_w', 200);
update_option('thumbnail_size_h', 200);
update_option('thumbnail_crop', 1);
//Setting medium size
update_option('medium_size_w', 400);
update_option('medium_size_h', 9999);
//Setting large size
update_option('large_size_w', 800);
update_option('large_size_h', 9999);
}
}
add_action( 'after_setup_theme ', 'theme_image_size_setup' );
Instead I have doing a work around solution, but it dosn’t feel optimal if there is a hook:
if ( is_admin() && isset($_GET['activated'] ) && $pagenow == 'themes.php' ) {
theme_image_size_setup();
}
This works… but why is there no respons on the after_setup_theme
hook?
This will only run when your theme has been switch TO from another theme. It’s the closest you can get to theme activation:
Or you can save an option in your wp_options table and check for that on each pageload, which a lot of people recommend even though it seems inefficient to me:
Maybe the problem could be that you have additional space inside this string
'after_setup_theme '
.Try it like this:
The after_setup_theme runs every time your page is load. so its not better solution.
Using WP 3.9 in a WPMU environment, there is an action called switch_theme which is called everything you switch a theme.
when this action is invoked the following $_GET parameters are passed: action=activate, stylesheet=
I created a new file in mu-plugins/theme-activation-hook.php