![Check out Enfold](https://kriesi.at/wp-content/themes/kriesi/images/banner-enfold.jpg)
-
AuthorPosts
-
September 3, 2018 at 7:57 am #1004803
i have enqueued a script on Enfold – that allows me to play only one youtube video at a time.
Clicking on a new youtube video this starts playing and the other playing goes to pause.
This script does not work – if js merging is active. _ maybe because it loads the YouTubeIframeAPI asynchron.is there a way to enqueue scripts and exclude them from merging?
Like bwp minify got this feature – but i like to have your merging tool – and not an additional Plugin.September 3, 2018 at 2:43 pm #1004988Hey Guenter,
https://cl.ly/da223d677705 From what I see here in the /enfold/config-templatebuilder/avia-template-builder/php/asset-manager.class.php, you can use the filter avf_exclude_assets to exclude files from being processed.
Best regards,
VictoriaSeptember 3, 2018 at 6:50 pm #1005111and how to apply this filter on my specific js file – with an absolute path to it or is it enough to have the js name.
i enqueued it only on few pages via:function youtube_single_js_script() { if ( is_page( array( 31239, 31341, 31464, 31484, 31824, 32089, 32257 ))) { wp_enqueue_script( 'Youtube-Single', get_stylesheet_directory_uri().'/js/youtube-singleplay.js', array('jquery'), '1.0', true ); } } add_action( 'wp_enqueue_scripts', 'youtube_single_js_script' );
are the scripts we load via Child-Theme functions.php even included in merging? If then it has more to do with the fact that the merged files are now below this embedded script.
September 4, 2018 at 7:36 am #1005304so my observation now is that these files enqueued by child-theme functions.php or some plugins are not included in merging process.
The Script files goes to a footer merged file and this is behind my script. Don’t know why this is important for the script to work.
My trial to include these scripts of the functions.php of my child-theme via :add_filter('avf_merge_assets', function() { return array('css' => 'all', 'js' => 'all'); });
does not work – they were not included.
Edit: bwp-minify does include those files and the script works in this constallation. ( Enfold disable merging via Enfold Options)September 4, 2018 at 8:58 am #1005324Hi,
You can use this code to exclude (additional) files:
add_filter('avf_exclude_assets', 'avia_exclude_files_from_compression', 10, 1); function avia_exclude_files_from_compression($excluded_files) { $exclude_css = array('admin-bar', 'dashicons'); $exclude_js = array('jquery-core', 'admin-bar', 'comment-reply'); $excluded_files['css'] = array_merge($excluded_files['css'], $exclude_css); $excluded_files['js'] = array_merge($excluded_files['js'], $exclude_js); return $excluded_files; }
Replace ‘admin-bar’, ‘dashicons’ with the names of your css files (i.e. the example files would be admin-bar.css and dashicons.css) and ‘jquery-core’, ‘admin-bar’, ‘comment-reply’ with the names of your js files (i.e. the example files would be jquery-core.js and admin-bar.js and comment-reply.js).
Best regards,
DudeSeptember 4, 2018 at 1:15 pm #1005536thanks Dude – but this file is not compressed / merged by default.
what about the trial to force include this file – i tried this:
add_filter('avf_force_include_asset', 'avia_force_include_files', 10, 1); function avia_force_include_files($force_included) { $force_include_js = array('youtube-singleplay'); $force_included['js'] = array_merge($force_included['js'], $force_include_js); return $force_included; }
but it does not include that little external script (enqueued via child-theme functions.php)
do i have to give in this line the path to the script:
$force_include_js = array('youtube-singleplay');
by the way you can see script in action here ( but with bwp minify): https://webers-testseite.de/youtube-videos/
Password is : Enfold
start one video and than the next without stopping the first.
because i don’t want to style every test-page DSGVO konform (GDPR)September 4, 2018 at 1:42 pm #1005548Hi,
Please create me an admin account and I’ll debug the code. Please make sure the theme file editor (Appearance > Editor) is not blocked.
Best regards,
DudeSeptember 4, 2018 at 4:36 pm #1005674aber sei bitte vorsichtig, das ist meine große Testseite wo ich allen möglichen Code ausprobiere.
meine functions.php des child-themes hat alleine schon 1200 zeilen !
ich habe nochmal ein Duplicator Backup gemacht – also keine Angst. Es ist alles irgendwie gesichertSeptember 4, 2018 at 4:40 pm #1005677Wie gesagt – selbst wenn das Merging von js und css an ist, ist dieses extern eingebundene Script nicht bei den gemergeten Files dabei.
Deshalb wollt ich testen, ob man dieses Script einfach mit einbindet in das Merging. deshalb mein Versuch über das andere Filter es einzubinden.September 6, 2018 at 12:07 pm #1006550Hallo Günter,
Tatsächlich ein bug – danke dafür.
Im File enfold\config-templatebuilder\avia-template-builder\php\asset-manager.class.php um Zeile 242 findest Du:
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 ))
Bitte ersetzen durch:
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 ] ) ) )
Im Filter avf_force_include_asset dann nur mehr den Namen angeben – in Deinem Fall youtube-singleplay.
Hab einen Pullrequest fürs nächste Update angelegt.
LG,
GünterSeptember 6, 2018 at 10:26 pm #1006822Danke fürs schnelle Feedback.
Leider wird das script auch so nicht eingebunden in das Merging ?
September 7, 2018 at 10:07 am #1007011Hi,
Hast du den Namen genommen, den Du in wp_enqueue_script verwendet hast (case sensitive !!!):
wp_enqueue_script( 'Youtube-Single', get_stylesheet_directory_uri().'/js/youtube-singleplay.js', array('jquery'), '1.0', true );
d.h.
add_filter('avf_force_include_asset', 'avia_force_include_files', 10, 1); function avia_force_include_files($force_included) { $force_include_js = array('Youtube-Single'); $force_included['js'] = array_merge($force_included['js'], $force_include_js); return $force_included; }
LG
GünterSeptember 7, 2018 at 10:16 am #1007018natürlich nicht – sorry – ich habe den Titel des js genommen – Asche auf mein Haupt
Edit : es funktioniert ! – aber kommt nicht zu dem günschten Erfolg.
Kann ich Einfluss nehmen an welcher Stelle das Script mit in das Merging genommen wird?
PS: wenn ich das gemergete File nehme und mal durch einen beautifier laufen lasse sehe ich , dass das Script so eingefügt wurde:
})(jQuery);; // vorheriges Script Ende - hier sind zwei Semicolon ? kann das Einfluss haben ? var tag = document.createElement('script'); // mein Script
PS : ich arbeit jetzt mal selbst dran – vielleicht ist es nicht gut wenn wir gleichzeitig als Admin drin sind und dran arbeiten.
-
This reply was modified 6 years ago by
Guenni007.
September 7, 2018 at 10:26 am #1007023Hi,
Versuche es mit:
add_action( 'wp_enqueue_scripts', 'youtube_single_js_script', 1 );
Sollte das nicht gehen mit:
add_action( 'init', 'youtube_single_js_script', 1 );
Best regards,
GünterSeptember 7, 2018 at 12:03 pm #1007075von Enfold Seite klappt wohl alles soweit –
ich habe es mal mit 9999 eingebunden und dann steht es definitv am Ende der Komprimierten Files.
Mein Gedanke war, dass die Reihenfolge in der es aufgerufen wird wichtig ist – denn die gemergeten Files liegen ja dann hinter dem nicht eingebundenem Script. – BWP Minify macht das so. Die komprimierten Files werden vor diesem Script aufgerufen.Egal – wenn ich es brauchen sollte, dann nehme ich halt BWP Minify für diese spezielle Seite dann.
Kann geschlossen werden.September 7, 2018 at 4:09 pm #1007165 -
This reply was modified 6 years ago by
-
AuthorPosts
- You must be logged in to reply to this topic.