What's wrong with this function? Trying to run code on theme activation only

What's wrong with this function? Trying to run code on theme activation only

The function below is supposed to fire when the theme it belongs to is activated. However, to get it to actually create the categories inside the conditional, I'm having to (1) activate the theme, (2) Activate any other theme (3) Activate the theme again

What gives, it should process upon the first time its activated.

// with activate make sure utility categories are created and parented correctly if ( is_admin() && isset($_GET['activated'] ) && $pagenow == 'themes.php' ) {      if (file_exists(ABSPATH.'/wp-admin/includes/taxonomy.php'))     {         require_once(ABSPATH.'/wp-admin/includes/taxonomy.php');              wp_create_category('nofollow');         $myCategory1['cat_ID'] = get_cat_id('nofollow');         $myCategory1['category_parent'] = 1;         wp_update_category($myCategory1);          wp_create_category('noindex');         $myCategory2['cat_ID'] = get_cat_id('noindex');         $myCategory2['category_parent'] = 1;         wp_update_category($myCategory2);      } } 

Google custom search results page don't show any results


What is the correct way to setup “Pretty” permalinks in Wordpress 3.0
I answered this in your another question, then saw it here. Get this code I made to also do month/day/week post count? Wordpress Hopefully the same answer applies and works with your re-activation conundrum. what the best solution for user driven content on my website Try using this hook instead of your $_GET request, and maybe you need to make this a plugin instead of putting it in your functions.php file to receive it to run when the theme is activated. Iterate through custom post type by custom taxonomy type? (Ordering wordpress posts by category, or displaying custom post type by taxonomy term) Previous answer follows:. Dissallow robots for a while You'll want to use an action hook. Custom Post Type and Taxonomy Permalink Rewrite in WordPress 3.0.1 Specifically, 'switch_theme'. Wordpress get_image_tag filter - change image attributes? This is the codex page for all action hooks, I can't link to switch_theme specifically, although scroll down and you'll find it. There is no specific information on this hook, although usage is simple. You must include your function in functions.php or in a plugin file, and after the function definition, include this hook:.
function add_my_categories($my-theme-name){         //if $my-theme-name == 'my_theme_name             //test if category exists             //if exists, update             //if doesn't exist, create and assign parent     } add_action('switch_theme','add_my_categories'); 
the 'add_action()' call will run the named function when the named hook is encountered in wordpress. The 'switch_theme' hook runs after a theme is changed.. It's important to know this this hook will provide the name of the new current theme to your function, which must accept it as an argument if you need it. For instance, to make sure the function only runs if your theme is the one activated. I suppose if this function is in your theme's functions.php file, it will NEVER run unless your theme is activated, so you must determine if you need to double check the theme name..

91 out of 100 based on 56 user ratings 851 reviews