简体   繁体   中英

wp.customize, get value from a setting and store in a variable

I am currently working on the theme options for a custom theme for a client. For further use i want to store a few settings inside variables during the page load of the customizer screen.

After a bit of a struggle i used wp.customize object to get the value of the setting i required and store it inside the variable. However the information of the variable can not be accessed outside of the function, even tho i declared the variable outside of the function. I have posted the function below.

The console log inside the function posts the value that i need. The console log outside of the function returns undefined. I would like some help on getting this to work.

Thank you in advance, Nick

var e_linkedin;
var e_facebook;
var e_twitter;
var e_google;

wp.customize( 'theme_social[enable_facebook]', function( value ) {
    e_facebook = value['_value'];
    console.log(e_facebook);

});
console.log(e_facebook);

您可以像这样从定制器访问变量:

var yourval = wp.customize.value( 'theme_social[enable_facebook]' )();

使用value._value访问value参数。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM