Skip Navigation

[Resolved] Dequeue unwanted scripts and embedded snippets

This support ticket is created 7 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Nigel 7 years, 6 months ago.

Assisted by: Nigel.

Author
Posts
#516292

Views is loading these files, I need to dequeue them but I can't:

mediaelement/mediaelement-and-player.min.js?ver=2.22.0
js/mediaelement/wp-mediaelement.min.js?ver=4.7.4
js/mediaelement/wp-playlist.min.js?ver=4.7.4
plugins/wp-views/embedded/res/js/wpv-pagination-embedded.js?ver=2.3.1
js/wp-embed.min.js?ver=4.7.4
js/jquery/ui/datepicker.min.js?ver=1.11.4

and here are some snippets of code, that are loaded which I don't use/need:

<script type="text/html" id="tmpl-wp-playlist-current-item">
	<# if ( data.image ) { #>
	<img src="{{ data.thumb.src }}" alt="" />
	<# } #>
	<div class="wp-playlist-caption">
		<span class="wp-playlist-item-meta wp-playlist-item-title">&#8220;{{ data.title }}&#8221;</span>
		<# if ( data.meta.album ) { #><span class="wp-playlist-item-meta wp-playlist-item-album">{{ data.meta.album }}</span><# } #>
		<# if ( data.meta.artist ) { #><span class="wp-playlist-item-meta wp-playlist-item-artist">{{ data.meta.artist }}</span><# } #>
	</div>
</script>
<script type="text/html" id="tmpl-wp-playlist-item">
	<div class="wp-playlist-item">
		<a class="wp-playlist-caption" href="{{ data.src }}">
			{{ data.index ? ( data.index + '. ' ) : '' }}
			<# if ( data.caption ) { #>
				{{ data.caption }}
			<# } else { #>
				<span class="wp-playlist-item-title">&#8220;{{{ data.title }}}&#8221;</span>
				<# if ( data.artists && data.meta.artist ) { #>
				<span class="wp-playlist-item-artist"> &mdash; {{ data.meta.artist }}</span>
				<# } #>
			<# } #>
		</a>
		<# if ( data.meta.length_formatted ) { #>
		<div class="wp-playlist-item-length">{{ data.meta.length_formatted }}</div>
		<# } #>
	</div>
</script>
<script type='text/javascript'>
jQuery(document).ready(function(jQuery){jQuery.datepicker.setDefaults({"closeText":"Close","currentText":"Today","monthNames":["January","February","March","April","May","June","July","August","September","October","November","December"],"monthNamesShort":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"nextText":"Next","prevText":"Previous","dayNames":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"dayNamesShort":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"dayNamesMin":["S","M","T","W","T","F","S"],"dateFormat":"MM d, yy","firstDay":1,"isRTL":false});});
</script>
<script type='text/javascript'>
/* <![CDATA[ */
var mejsL10n = {"language":"en-US","strings":{"Close":"Close","Fullscreen":"Fullscreen","Turn off Fullscreen":"Turn off Fullscreen","Go Fullscreen":"Go Fullscreen","Download File":"Download File","Download Video":"Download Video","Play":"Play","Pause":"Pause","Captions\/Subtitles":"Captions\/Subtitles","None":"None","Time Slider":"Time Slider","Skip back %1 seconds":"Skip back %1 seconds","Video Player":"Video Player","Audio Player":"Audio Player","Volume Slider":"Volume Slider","Mute Toggle":"Mute Toggle","Unmute":"Unmute","Mute":"Mute","Use Up\/Down Arrow keys to increase or decrease volume.":"Use Up\/Down Arrow keys to increase or decrease volume.","Use Left\/Right Arrow keys to advance one second, Up\/Down arrows to advance ten seconds.":"Use Left\/Right Arrow keys to advance one second, Up\/Down arrows to advance ten seconds."}};
var _wpmejsSettings = {"pluginPath":"\/wp-includes\/js\/mediaelement\/"};
var mejsL10n = {"language":"en-US","strings":{"Close":"Close","Fullscreen":"Fullscreen","Turn off Fullscreen":"Turn off Fullscreen","Go Fullscreen":"Go Fullscreen","Download File":"Download File","Download Video":"Download Video","Play":"Play","Pause":"Pause","Captions\/Subtitles":"Captions\/Subtitles","None":"None","Time Slider":"Time Slider","Skip back %1 seconds":"Skip back %1 seconds","Video Player":"Video Player","Audio Player":"Audio Player","Volume Slider":"Volume Slider","Mute Toggle":"Mute Toggle","Unmute":"Unmute","Mute":"Mute","Use Up\/Down Arrow keys to increase or decrease volume.":"Use Up\/Down Arrow keys to increase or decrease volume.","Use Left\/Right Arrow keys to advance one second, Up\/Down arrows to advance ten seconds.":"Use Left\/Right Arrow keys to advance one second, Up\/Down arrows to advance ten seconds."}};
var _wpmejsSettings = {"pluginPath":"\/wp-includes\/js\/mediaelement\/"};
/* ]]> */
</script>
<script type='text/javascript'>
/* <![CDATA[ */
var wpv_pagination_local = {"front_ajaxurl":"https:\/\/soukplus.com\/wp-admin\/admin-ajax.php","calendar_image":"https:\/\/soukplus.com\/wp-content\/plugins\/wp-views\/embedded\/res\/img\/calendar.gif","calendar_text":"Select date","datepicker_min_date":null,"datepicker_max_date":null,"resize_debounce_tolerance":"100","datepicker_style_url":"https:\/\/soukplus.com\/wp-content\/plugins\/wp-views\/embedded\/toolset\/toolset-common\/toolset-forms\/css\/wpt-jquery-ui\/jquery-ui-1.11.4.custom.css"};
/* ]]> */
</script>

Here's the php in my functions.php but it does nothing:

add_action('wp_enqueue_scripts', 'cleanup_scripts', 11);
function cleanup_scripts() {
if (!is_admin()) {
global $WP_Views;
wp_dequeue_style( 'views-pagination-style' );

wp_dequeue_script( 'wpv-front-end-utils' );
wp_dequeue_style( 'views-table-sorting-style' );
wp_dequeue_style( 'wpv_render_css' );
wp_dequeue_script( 'jquery-ui-core' );
wp_dequeue_script( 'jquery-ui-datepicker' );
wp_dequeue_script( 'jquery-ui-datepicker-local' );
wp_dequeue_script( 'wpv-date-front-end-script' );
remove_action('wp_print_styles', array($WP_Views, 'add_render_css'));
remove_action('wp_head', 'wpv_add_front_end_js');
}
}

Please help me rid of these bloats!

Thanks

#516457

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Andy

Toolset has its own system for enqueuing styles and scripts, but it is still based upon the standard WordPress registering and enqueuing functions, and you should be able to dequeue the unwanted scripts or styles before they are added to the page.

The recommended hooks to use are wp_print_scripts and wp_print_styles respectively, which run immediately prior to the scripts and style links being printed to the page. Used with a late priority it will ensure you are attempting to dequeue them once they have been enqueued.

Here is a simple example I used to dequeue the pagination script and stylesheet from the front-end:

function cleanup_scripts() {

	if ( !is_admin() ) {

		wp_dequeue_script( 'views-pagination-script' );

	}
}
add_action( 'wp_print_scripts', 'cleanup_scripts', 100 );

function cleanup_styles() {

	if ( !is_admin() ) {

		wp_dequeue_style( 'views-pagination-style' );

	}
}
add_action( 'wp_print_styles', 'cleanup_styles', 100 );

I don't recognise the code snippets for the media player controls, do you know what is adding them?

The datepicker script is a dependancy of the pagination script, so removing that should remove datepicker, too, unless something else is trying to add it.

#516680

<cite>I don't recognise the code snippets for the media player controls, do you know what is adding them?</cite>

This is added with views, when I deactivate views it isn't added.

Thanks

#516802

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Andy

It looks like the media element files are dependencies for the Views navigation script which my sample code dequeues, so I'm not sure why they are still being loaded.

By dequeuing views-pagination-script it removes those dependencies at the same time. On my local test site that's what I experience, removing views-pagination-script also dequeues the media element and playlist scripts.

Can I just check, are you still seeing those scripts added after adding the code to dequeue views-pagination-script?

#517106

yes it removes it, however I am in a catch 22.

I will need the pagination script so will it be possible to remove the datepicker without removing the pagination?

#517555

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Andy

Sorry for the delay getting back to you.

Well, the datepicker script is declared as a dependency of the pagination script, so if you leave the pagination script enqueued WordPress will automatically and unavoidably load the datepicker script, too.

The only solution I can think of is to dequeue the pagination script and the re-enqueue it yourself, without specifying datepicker as a dependency (you'll probably want to specify at least jQuery as a dependency).

I haven't tried it and can't be sure it would work but given how the pagination script is currently enqueued by Views there is no other means I can think of.

If you do try let me know how you get on as I would be curious to know.