WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been tasked with creating a theme that will be a base to list the site owners ebay store products.

I have fleshed most of the project out in plain old php to get everything working as regards to adding the listings via the ebay api, right now im integrating the code into functions.php of the custom theme.

What i need to do is create database tables in WP to hold the ebay xml file values from various xml files, following the codex i can see how it is done via plugin activation, My question is how can i do it directly via the themes functions.php on theme activation following the codex it does not work which im guessing is down to require_once ABSPATH

share|improve this question
up vote 7 down vote accepted

In functions.php you can create "your_set_tables_function()" and then hook it in the "after_switch_theme" hook.


add_action("after_switch_theme", "your_set_tables_function");
share|improve this answer
Thanks, that now works flawlessly – MartinJJ Dec 13 '12 at 23:16

Create a function called theme_activation_function and execute the code that creates your table inside it.

By adding the after_switch_theme action, when YOUR theme is enabling the function runs! :)

<?php add_action('after_switch_theme', 'theme_activation_function'); ?> 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.