Title: call cmb2_get_options in functions.php
Last modified: September 1, 2016

---

# call cmb2_get_options in functions.php

 *  Resolved [Quentin](https://wordpress.org/support/users/qur/)
 * (@qur)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/call-cmb2_get_options-in-functioncphp/)
 * Hello,
 * I am trying to use a theme options page to include or not files in my functions.
   php.
    But I get this : Fatal error: Call to undefined function cmb2_get_option().
   I can’t understand the different answers I have found around. I guess this is
   because, functions.php is loaded before the plugins?
 * This is what I need:
    if ((myprefix_get_option( ‘settings_events’ ) == ‘on’)){
   require_once($tempdir .’/inc/myprefix_calendar.php’); }
 * Or maybe there is a better way and not include this in functions.php but can’t
   see where. How can I use my theme options in functions.php ?
 * Best regards,
 * Quentin
 * [https://wordpress.org/plugins/cmb2/](https://wordpress.org/plugins/cmb2/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Justin Sternberg](https://wordpress.org/support/users/jtsternberg/)
 * (@jtsternberg)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/call-cmb2_get_options-in-functioncphp/#post-7501377)
 * Try this:
 *     ```
       function myprefix_cmb2_after_init_include_calendar() {
       	if ( 'on' === myprefix_get_option( 'settings_events' ) ) {
       		require_once( $tempdir .'/inc/myprefix_calendar.php' );
       	}
       }
       add_action( 'cmb2_after_init', 'myprefix_cmb2_after_init_include_calendar' );
       ```
   
 * Basically, you can’t use CMB2 functionality until it’s been initiated. If you
   use this hook, you can be sure all CMB2 functionality has been bootstrapped.
 *  Thread Starter [Quentin](https://wordpress.org/support/users/qur/)
 * (@qur)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/call-cmb2_get_options-in-functioncphp/#post-7501520)
 * Hello,
 * Thanks for the reply. It seems to be partly working.
    But maybe what I am trying
   to do does not work like that. I have an option page with a checkbox. When it
   is checked I wanted to include the file myprefix_calendar.php which loads a custom
   post type “Events”. But maybe this can’t be done like this as it is loaded after
   init, does cpt need to be load inside init?
 * Best regards,
 * Quentin
 *  Thread Starter [Quentin](https://wordpress.org/support/users/qur/)
 * (@qur)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/call-cmb2_get_options-in-functioncphp/#post-7501525)
 * Maybe I should activate my custom post types and have an option to show or hide
   it in admin and frontend.
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [9 years, 11 months ago](https://wordpress.org/support/topic/call-cmb2_get_options-in-functioncphp/#post-7501574)
 * Yes, post types should be registered on the init hook, as per the register_post_type
   codex page.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘call cmb2_get_options in functions.php’ is closed to new replies.

 * ![](https://ps.w.org/cmb2/assets/icon.svg?rev=2866672)
 * [CMB2](https://wordpress.org/plugins/cmb2/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cmb2/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cmb2/)
 * [Active Topics](https://wordpress.org/support/plugin/cmb2/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cmb2/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cmb2/reviews/)

 * 4 replies
 * 3 participants
 * Last reply from: [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * Last activity: [9 years, 11 months ago](https://wordpress.org/support/topic/call-cmb2_get_options-in-functioncphp/#post-7501574)
 * Status: resolved