0

I would love to integrate Custom CSS field from my Option Tree plugin to the code, but if I try to integrate them following way into functions.php, it ends up with Fatal error: Call to undefined function ot_get_option() in /data/web/virtuals/51889/virtual/www/domains/demo.kybernaut.cz/ommo-wp/wp-content/themes/ommo/functions.php on line 36 So it looks like that I call the function before loading ot_get_option function from Option tree, is that possible? What to do with it? Thanks a lot!

//Custom CSS
    if (ot_get_option('css', false) != false) {
        function css() {
            return '<style>'.ot_get_option('css').'</style>';   
        }
        add_action( 'wp_head', 'css', 100 );
    }
3
  • What is Option Tree? How is definition of that function loaded and at which point during load?
    – Rarst
    Nov 7, 2015 at 21:05
  • Its a plugin from repo link for creating the Theme Options. Nov 7, 2015 at 21:11
  • 1
    css is an incredibly generic function name, it's going to cause issues for you further down the line, consider adding a prefix or namespace
    – Tom J Nowell
    Nov 8, 2015 at 4:35

1 Answer 1

4

never* execute code outside of hooks as you are more likely to call a function or use a variable before they were declared and initialized.

your code should be

function css() {
    if (ot_get_option('css', false) != false) {
            echo'<style>'.ot_get_option('css').'</style>';   
        }
    }

add_action( 'wp_head', 'css', 100 );

*never say never, but this is a rule to follow unless you have a very explicit reason to ignore it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.