-
AuthorPosts
-
July 2, 2020 at 12:48 pm #1227472
We see on functions.php the conditionally loading of the scripts – needed for some enfold functions.
F.e. the lightbox script or the shrinking header script etc.
I did this without the condition set in the functions.php because i do know if i use lightbox on my installation or not.But how would such an integration look correct if I wanted to include the condition.
there was a topic here to influence the mouseenter mouseleave delay. What if i like to have a child-theme: avia-snippet-megamenu.jswould this be the right way? :
add_action( 'wp_enqueue_scripts', 'wp_change_megamenu_script', 100 ); function wp_change_megamenu_script() { wp_deregister_script( 'avia-megamenu' ); $condition = (avia_get_submenu_count('avia') > 0); wp_enqueue_script( 'avia-megamenu-child', get_stylesheet_directory_uri().'/js/avia-snippet-megamenu.js', array('avia-default'), $vn, true); }
July 6, 2020 at 7:04 pm #1228345Hey Guenter,
Thank you for the inquiry.
You will probably need the avia_enqueue_script_conditionally function and pass the condition to it. If condition is true, register the script, if not then deregister it.
Best regards,
IsmaelJuly 7, 2020 at 9:38 am #1228510this way ?
add_action( 'wp_enqueue_scripts', 'wp_change_megamenu_script', 100 ); function wp_change_megamenu_script() { wp_deregister_script( 'avia-megamenu' ); $condition = (avia_get_submenu_count('avia') > 0); avia_enqueue_script_conditionally( $condition , 'avia-megamenu-child', get_stylesheet_directory_uri().'/js/avia-snippet-megamenu.js', array('avia-default'), $vn, true); }
July 10, 2020 at 10:37 am #1229370Hi,
Yes, that looks about right. More examples can be found in the functions.php file inside the avia_register_frontend_scripts function.
Best regards,
IsmaelJuly 17, 2020 at 1:55 pm #1231282thanks Ismael and – of course you can close the topic now
Too early:
i tested it on shrinking script and:add_action( 'wp_enqueue_scripts', 'wp_change_sticky_header_script', 100 ); function wp_change_sticky_header_script() { wp_deregister_script( 'avia-sticky-header' ); $condition = (isset($options['header_position']) && $options['header_position'] == "header_top"); $condition2 = (isset($options['header_sticky']) && $options['header_sticky'] == "header_sticky") && $condition; avia_enqueue_script_conditionally( $condition2 , 'avia-sticky-header-child', get_stylesheet_directory_uri().'/js/avia-snippet-sticky-header.js', array('avia-default'), $vn, true); }
i tought that this is the right code but on my shrinking script i see that this is not working that way.
July 19, 2020 at 7:18 am #1231527 -
AuthorPosts
- The topic ‘how to load a child-theme avia-default script conditionally’ is closed to new replies.