Home › Forums › Add-ons › Options Page › How to initiate Theme Setting on theme activate without having to click "Update" › Reply To: How to initiate Theme Setting on theme activate without having to click "Update"
There are two choices. What I would call easy and difficult.
First the difficult:
Register a theme activation hook https://codex.wordpress.org/Function_Reference/register_activation_hook. In your activation function insert the needed data into the database by way of update_field() http://www.advancedcustomfields.com/resources/update_field/
Then the easy and the way that I prefer to do things:
(Actually, I only use the get_post_meta() and get_option() WP functions in my themes so that they won’t crash a site should ACF get deactivated, but that’s another story)
Set the default value in the theme file
// with ACF, longhand
$value = 'the default_value';
$option = get_field('my_field_name', 'option');
if ($option) {
$value = $option.
}
// with get_option
$value = get_option('options_'.'my_field_name', $default_value);
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.