Support

Account

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);