[wp-hackers] Reacting to options (theme options) in Javascript
Otto
otto at ottodestruct.com
Wed Aug 11 19:37:35 UTC 2010
Just enqueue the JS or not based on the option. You can do this in
your functions.php file in the theme.
function themename_js() {
if (get_option('whatever') == 'something) {
wp_enqueue_script('yourscript','whatever',...);
}
}
add_action('wp_print_scripts','themename_js');
Then your script gets added to the page or not added to the page based
on your option.
-Otto
On Wed, Aug 11, 2010 at 2:02 PM, [ ravi ] <ravi-lists at g8o.net> wrote:
>
> Howdy all,
>
> I have a preference setting in my theme options. If it is checked on, then some jQuery stuff needs to be activated. The jQuery stuff sits in a .js file in my theme. Thus far, I have been throwing this sort of Javascript code, that has to be executed on the basis of a back-end option, in a separate PHP file with wrapper PHP code that checks for the relevant option(s).
>
> I am wondering if anyone has a cleverer way of achieving the same thing?
>
> Cheers,
>
> —ravi
>
>
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list