Loading additional scripts for CF7
-
Hello there,
I would like to load additional scripts to cf7. Particularly, I have two kind of scripts: CondAll.js, to be loaded for every form; CondXXX.js, to be loaded for form XXX only if the file CondXXX is found in a certain directory.
I wrote down (and added to functions.php in my child theme) the following code:
function wpcf7_loadConditions($wpcf7_data) { $formId = $wpcf7_data->id(); if (is_null($formId) ) {return;} /* Conditions for all forms */ wp_enqueue_script('CondAll', get_stylesheet_directory_uri() . '/js/CondAll.js', array('jquery')); /* END of conditions for all forms */ /* Conditions for multiple forms selected by their id */ if ( in_array($formId, array(1,2,3)) ) { } /* END of conditions for multiple forms selected by their id */ /* Conditions for single form based on its id */ if ( $formId == 1 ) ) { } /* END of conditions for single form based on its id */ /* Conditions for forms based on the presence of a CondXXX.js file where XXX = form id */ $myBaseURL = get_stylesheet_directory_uri() . '/js/'; $hookName = 'Cond' . $formId; $condFile = $myBaseURL . $hookName . '.js'; if (file_exists($condFile)) { wp_enqueue_script($hookName, $condFile, array('jquery')); } /* END of conditions for forms based on the presence of a CondXXX.js file where XXX = form id*/ } add_action('wp_enqueue_scripts', 'wpcf7_loadConditions');The code makes WP crash; what am I doing wrong?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Loading additional scripts for CF7’ is closed to new replies.