Forum Replies Created
-
AuthorPosts
-
December 22, 2018 at 11:06 pm in reply to: merge jQuery, own-child.js and avia-footer-scripts into one #1048709
Here is what I found (unfortunately without help from the support-team).
You can merge your own custom.js files with the merging-files option from enfold.
See: https://kriesi.at/support/topic/add-own-script-js-file-to-avia-footer-scripts-js/#post-1048707It seems to not be possible to add the jQuerry.js file into it that simple (the backend admin-section also uses it for example). Maybe someone has a good solution for it?
Is it possible to merge the files, only when no admin-user is logged in, and just the page is served to the user?December 22, 2018 at 10:58 pm in reply to: Add own script.js file to avia-footer-scripts.js #1048707Thanks a lot Guenni007,
your hint was really helpful. Here is the solution:
To achieve merging your custom .js files with all other .js files you need to do three things:
Go to you parent enfold themes folder:
wp-content/themes/enfold/config-templatebuilder/avia-template-builder/php/asset-manager.class.phpOn line 242 you will see the following code:
if( ('all' == $this->which_files[$file_type] ) || ('avia-module' == $this->which_files[$file_type] && strpos($file, 'avia-module') !== false ) || ('avia' == $this->which_files[$file_type] && strpos($file, 'avia') !== false ) || ( $force_print ))
This code has a bug, go and change it to:
// ------------------------------------------------------- // Bugfix - old code // ------------------------------------------------------- // if( ('all' == $this->which_files[$file_type] ) || // ('avia-module' == $this->which_files[$file_type] && strpos($file, 'avia-module') !== false ) || // ('avia' == $this->which_files[$file_type] && strpos($file, 'avia') !== false ) || // ( $force_print )) // ------------------------------------------------------- // new Code // ------------------------------------------------------- if( ('all' == $this->which_files[$file_type] ) || ('avia-module' == $this->which_files[$file_type] && strpos($file, 'avia-module') !== false ) || ('avia' == $this->which_files[$file_type] && strpos($file, 'avia') !== false ) || ( $force_print ) || ( in_array( $file, $this->force_include[ $file_type ] ) )) // ------------------------------------------------------- // end of new Code // -------------------------------------------------------
After it, go and include your custom.js file in your child-theme functions.php like this:
/** load and merge custom.js with other theme .js files */ function custom_scripts() { wp_enqueue_script( 'Child-JS', get_stylesheet_directory_uri().'/js/custom.js', array('jquery'), '1.0', true ); } add_action( 'wp_enqueue_scripts', 'custom_scripts' ); add_filter('avf_force_include_asset', 'avia_force_include_files', 10, 1); function avia_force_include_files($force_included) { $force_include_js = array('Child-JS'); $force_included['js'] = array_merge($force_included['js'], $force_include_js); return $force_included; }
The last step is to acitvate file-merging of corse:
Enfold Child Theme Options -> Leistung (should be something like performance in EN) -> there:
Enable Javascript file merging and compressionThat should do the trick. Again a big thank to Guenni007.
- This reply was modified 5 years, 11 months ago by fecgz.
-
AuthorPosts