On/Off button Control in functions.php


#1

Hello…

I’m tring to using OptionTree framework. But, I need help.

I created custom post types and I want to control them with theme options panel.

If user want to use one of them, he must activate it from options panel, but I can’t control it. For control using on/off button.

Functions.php: Functions.php

How can I check the button is on or off?

OptionsPanel works very well.

Thanks.


#2

Functions.php: http://pastie.org/9142617


#3

Hi there:

I don’t am programmer, I don’t can help you :’( .
your patience other author or staff can help you :wink: regards.


#4

Im not sure how far you are in your development but I would advise using wordpress customizer for theme options. In which case below should work. If not something similar might work.

<?php if(get_option('option-name') == 1) : ?>

hello

<?php endif; ?>

#5

I’ve changed the code;

if (get_option_tree( ‘references’, ‘on’ )) {
require_once( get_template_directory() .’/content/references.php’ );
}

Activated debug mode. Now, I’m taking this message;

Call to undefined function get_option_tree() in functions.php


#6

Never used optiontree, so Im not sure if you are doing something wrong, but it could be because you are calling the function before the OT framework is initialized. In which case, you should move option tree functions to a separate file ‘theme-functions.php’ and call the functions there. Then just require get_template_directory() . ‘/inc/theme-functions.php’ in your functions file after OT init.


#7

OptionTree works very well…

When I use the codes fronted, it shows. The matter that I can’t use the codes in functions.php


#8

My friend thats what I mean, you are probably writing the function before wordpress has initialized option tree framework hence get_option_tree() is an undefined function. Either move it after Option tree is initialized or move it to a separate file and require that file in your functions.php


#9

Moved the codes to theme_setup function. Now it works.

Thanks @codeblvck.


#10

You are welcome buddy, good luck!