WordPress.org

Ready to get started?Download WordPress

Forums

OptionTree
[resolved] Undefined function (3 posts)

  1. fredmat
    Member
    Posted 3 months ago #

    First, big thanks for your plugin!

    I'm using it as plugin, and my problem is when I call ot_get_option() in my functions.php or any other file, PHP says that its undefined function.

    Any idea?

    Thanks!

    https://wordpress.org/plugins/option-tree/

  2. Derek Herman
    Member
    Plugin Author

    Posted 3 months ago #

    OptionTree is loaded on the after_setup_theme action at priority 1. So if your theme is calling the ot_get_option() function before it's loaded you'll get an error message. A typical issue people run into is that they use the function inside the functions.php file before it's available with code like:

    $my_option = ot_get_option('option_id');
    echo $my_option;

    To solve the issue you would wrap that code like:

    function my_custom_function() {
      $my_option = ot_get_option('option_id');
      echo $my_option;
    }
    add_action( 'after_setup_theme', 'my_custom_function' );
  3. fredmat
    Member
    Posted 3 months ago #

    Actually I'd like to assign a constant with options data:

    define( 'CONSTANT', ot_get_option( 'my_option' );

    and this code is at top of functions.php

    thanks

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.