Support » Plugin: ALO EasyMail Newsletter » Unwanted script added to every page

  • khunmax



    I am only using your plugin widget on one page of my website.

    However the following code is being added to the source code of EVERY page of my website (Including my home page).

    Is there a filter I can add to my functions.php file to ensure your plugin only loads script on the single page where I display your widget?

    The code you plugins is adding to every page is as follows:

    function alo_em_user_form ( opt )
    			document.getElementById('alo_easymail_widget_feedback').innerHTML = '';
    			document.getElementById('alo_easymail_widget_feedback').className = 'alo_easymail_widget_error';
    			document.getElementById('alo_em_widget_loading').style.display = "inline";
    			var alo_em_sack = new sack(
    				"" );
    			alo_em_sack.execute = 1;
    			alo_em_sack.method = 'POST';
    			alo_em_sack.setVar( "action", "alo_em_user_form_check" );
    			alo_em_sack.setVar( "alo_easymail_option", opt );
    									alo_em_sack.setVar( "alo_easymail_txt_generic_error", 'Error during operation.' );
    			alo_em_sack.setVar( "alo_easymail_txt_success", 'Successfully updated' );
    			alo_em_sack.setVar( "alo_easymail_txt_need_sub", 'Before editing other fields you have to click the subscription choice' );
    			alo_em_sack.setVar( "alo_easymail_lang_code", 'en' );
    						var cbs = document.getElementById('alo_easymail_widget_form').getElementsByTagName('input');
    			var length = cbs.length;
    			var lists = "";
    			for (var i=0; i < length; i++) {
    				if (cbs[i].name == 'alo_em_form_lists' +'[]' && cbs[i].type == 'checkbox') {
    					if ( cbs[i].checked ) lists += cbs[i].value + ",";
    			alo_em_sack.setVar( "alo_em_form_lists", lists );
    			alo_em_sack.setVar( "alo_em_nonce", 'ca409e9be6' );
    			return true;
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author eventualo


    Hi khunmax, it’s a good remark. The code is included in every page because it’s necessary not only for the subscription page, but also for the widget: in this way you are free to add the widget in every page/sidebar of your blog.

    At the moment maybe there isn’t a smart way to detect if the widget is used in a sidebar of the requested page.
    In future I’ll search a solution about it.

    Normally it is possible to limit what page a plugin’s code will appear on using a short script in my functions.php file, or using an asset management plugin.

    However the problem is that those two solutions rely upon wp_enqueue_script and I cannot find that in the PHP for your plugin.

    So the way that your plugin is currently coded it is not possible for me to limit where it injects its script into my source code.

    I have been using your plugin for years (Thank You). But site speed is becoming increasingly important so I cannot continue to use your plugin because I have a alo widget on only one page, but your plugin injects script into the source code of all of my pages, including my home page.

    Kind Regards


    Plugin Author eventualo


    I understand your point.

    At the moment, you could remove the plugin default action that prints the script, then re-add the action only on the pages you need.

    In your functions.php you could add something like:

    remove_action('wp_head', 'alo_em_ajax_js' );
    function my_easymail_maybe_add_script () {
    	// The list of page slug with the widget
    	$pages_with_widget = array( 'newsletter', 'other-page-slug' );
    	if ( is_page( $pages_with_widget ) ) {
    		add_action('wp_head', 'alo_em_ajax_js' );
    add_action('init', 'my_easymail_maybe_add_script' );

    I’ve not tested but I think it can be a good starting point. Let us know.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Unwanted script added to every page’ is closed to new replies.