Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #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.js

    would 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);
    }
    #1228345

    Hey 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,
    Ismael

    #1228510

    this 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);
    }
    #1229370

    Hi,

    Yes, that looks about right. More examples can be found in the functions.php file inside the avia_register_frontend_scripts function.

    Best regards,
    Ismael

    #1231282

    thanks 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.

    #1231527

    Hi Günter,

    Great, I’m glad that Ismael could help you out :-)

    Please open a new thread if you should have any further questions or problems.

    Best regards,
    Rikard

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘how to load a child-theme avia-default script conditionally’ is closed to new replies.