Home Forums Add-ons Options Page Different info on how to add options page Reply To: Different info on how to add options page

  • What is correct depends on several things.

    You can simply call an ACF function in functions.php if ACF is installed as a plugin the standard way that a plugin is installed.

    If ACF is installed inside of the theme, which is possible, the only way that the above will work is if ACF is loaded before you call the function.

    It is safer to use either the init or acf/init hook. these are close to being the same, but not quite. ACF initializes at priority 10 on the init hook. In most cases using the init or acf/init are the same, again, this depends on how ACF is loaded.

    It is possible to cause a premature initialization of ACF by calling some function before ACF has been initialized on the init hook. It is almost always safer to use the acf/init hook to ensure that ACF is initialize normally.

    But, for 95% of users none of this matters because ACF is installed normally like other plugins and most calls to ACF will happen in the theme and ACF will already be initialized. All of the methods you’ve seen are interchangeable. The only time this is generally be an issue is if you’re trying to create a plugin that uses ACF. In this case you need to use acf/init to ensure that ACF has been loaded and initialized because in this case you can’t know if ACF will be loaded first or not. This depends on the order that plugins are activated and can change when plugins are updated.

    As far as using acf_add_options_page() instead of acf_add_options_sub_page(). Calling the first function with the “parent_slug” set is the same as calling the second function. However, calling the second function without setting “parent_slug” will cause ACF to use the default options page as the parent of the page you are creating.

    Hoping this makes sense.