custom header - Where is the Javascript attribute window._wpCustomHeaderSettings defined?

I'm trying to modify the behaviour of the Javascript function defined in wp-includesjswp-custom-header.js, to cha

I'm trying to modify the behaviour of the Javascript function defined in wp-includes/js/wp-custom-header.js, to change the minimum windows height to display a video header. For this, I need to modify the attribute window._wpCustomHeaderSettings.minHeight At the time that my script runs, window._wpCustomHeaderSettings is not defined yet, so I create it with a window._wpCustomHeaderSettings = window._wpCustomHeaderSettings || {}, then set the attribute minHeight to a value of 0.

However, after the page is loaded, if I use the browser console to display this attribute, I see that it has the default value of 500.

So I tried to see where this value was defined to understand what I was doing wrong, but I couldn't, despite all my greps through Wordpress source code.

I'm trying to modify the behaviour of the Javascript function defined in wp-includes/js/wp-custom-header.js, to change the minimum windows height to display a video header. For this, I need to modify the attribute window._wpCustomHeaderSettings.minHeight At the time that my script runs, window._wpCustomHeaderSettings is not defined yet, so I create it with a window._wpCustomHeaderSettings = window._wpCustomHeaderSettings || {}, then set the attribute minHeight to a value of 0.

However, after the page is loaded, if I use the browser console to display this attribute, I see that it has the default value of 500.

So I tried to see where this value was defined to understand what I was doing wrong, but I couldn't, despite all my greps through Wordpress source code.

Share Improve this question asked Aug 12, 2019 at 10:19 user153991user153991 1053 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

It's defined via wp_localize_script() that's called by the_custom_header_markup():

wp_localize_script( 'wp-custom-header', '_wpCustomHeaderSettings', get_header_video_settings() );

So if you want to override the values/settings using JavaScript, then you can hook to wp_print_footer_scripts and add your script like so:

add_action( 'wp_print_footer_scripts', function(){
    if ( wp_script_is( 'wp-custom-header' ) ) :
    ?>
        <script>
        if ( window._wpCustomHeaderSettings ) {
            _wpCustomHeaderSettings.minHeight = 0;
        }
        </script>
    <?php
    endif;
}, 11 );

But the variable name starts with _ which normally indicates a private variable that should never be "touched" (other than for reading its values), so I suggest you to use the header_video_settings filter instead to override the default minHeight (or any setting's) value:

add_filter( 'header_video_settings', function( $settings ){
    $settings['minHeight'] = 0;
    return $settings;
} );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745246936a4618451.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信