Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1303962

    in the enfold theme how can I move the js script avia_cookie_check_sessionStorage () in the footer? and remove it from the meta tags?

    <meta charset=”UTF-8″ />
    <!– mobile setting –>
    <meta name=”viewport” content=”width=device-width, initial-scale=1″>

    <!– Scripts/CSS and wp_head hook –>
    <meta name=’robots’ content=’index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1′ />

    <script type=’text/javascript’>

    function avia_cookie_check_sessionStorage()
    {
    // FF throws error when all cookies blocked !!
    var sessionBlocked = false;
    try
    {
    var test = sessionStorage.getItem( ‘aviaCookieRefused’ ) != null;
    }
    catch(e)
    {
    sessionBlocked = true;
    }

    var aviaCookieRefused = ! sessionBlocked ? sessionStorage.getItem( ‘aviaCookieRefused’ ) : null;

    var html = document.getElementsByTagName(‘html’)[0];

    /**
    * Set a class to avoid calls to sessionStorage
    */
    if( sessionBlocked || aviaCookieRefused )
    {
    if( html.className.indexOf(‘av-cookies-session-refused’) < 0 )
    {
    html.className += ‘ av-cookies-session-refused’;
    }
    }

    if( sessionBlocked || aviaCookieRefused || document.cookie.match(/aviaCookieConsent/) )
    {
    if( html.className.indexOf(‘av-cookies-user-silent-accept’) >= 0 )
    {
    html.className = html.className.replace(/\bav-cookies-user-silent-accept\b/g, ”);
    }
    }
    }

    avia_cookie_check_sessionStorage();

    </script>

    #1304444

    Hey Demia87,

    Thank you for the inquiry.

    We can nullify the original script by adding this script in the functions.php file.

    
    // a custom script
    // disable avia_cookie_check_sessionStorage
    function ava_custom_script_mod_cookie_check() {
        if ( wp_script_is( 'avia-default', 'registered' ) ) {
            wp_add_inline_script( 'avia-default', '
    		window.avia_cookie_check_sessionStorage = null;
    	');
        }
     }
     add_action( 'wp_enqueue_scripts', 'ava_custom_script_mod_cookie_check', 9999);
    

    Then use this code to add the script back to the footer. Please note that the original function will still exist but it should not work because it’s already nulled.

     
    /**
     * Add a script that removes the class av-cookies-user-silent-accept if local browser session has the cookie set
     * that user refused cookies. This is a fallback for enfold\js\avia-snippet-cookieconsent.js
     * 
     * As FF throws an error when cookies are disabled we have to add this workaround.
     * 
     * @since 4.6.4
     */
    function avia_cookie_check_session_storage_mod()
    {
    	$privacy = av_privacy_helper();
    
    	$option = $privacy->get_cookie_consent_message_bar_option();
    	if( 'disabled' == $option )
    	{
    		return;
    	}
    
    	$output  = '';
    	$output .= "
    		<script type='text/javascript'>
    
    		function avia_cookie_check_sessionStorage_mod()
    		{
    			//	FF throws error when all cookies blocked !!
    			var sessionBlocked = false;
    			try
    			{
    				var test = sessionStorage.getItem( 'aviaCookieRefused' ) != null;
    			}
    			catch(e)
    			{
    				sessionBlocked = true;
    			}
    			
    			var aviaCookieRefused = ! sessionBlocked ? sessionStorage.getItem( 'aviaCookieRefused' ) : null;
    			
    			var html = document.getElementsByTagName('html')[0];
    
    			/**
    			 * Set a class to avoid calls to sessionStorage
    			 */
    			if( sessionBlocked || aviaCookieRefused )
    			{
    				if( html.className.indexOf('av-cookies-session-refused') < 0 )
    				{
    					html.className += ' av-cookies-session-refused';
    				}
    			}
    			
    			if( sessionBlocked || aviaCookieRefused || document.cookie.match(/aviaCookieConsent/) )
    			{
    				if( html.className.indexOf('av-cookies-user-silent-accept') >= 0 )
    				{
    						html.className = html.className.replace(/\bav-cookies-user-silent-accept\b/g, '');
    				}
    			}
    		}
    
    		avia_cookie_check_sessionStorage_mod();
    
    	</script>
    	";
    
    	echo $output;
    }
    
     add_action("init", function() {
    	add_action( 'wp_footer', 'avia_cookie_check_session_storage_mod', 10 );
     }, 25);
    
    

    Best regards,
    Ismael

    #1304659

    hi Ishmael, I inserted your code in the enfold child theme in function.php file, but no effect, I still see the avia_cookie_check_sessionStorage function between the meta tags

    #1305176

    Hi,

    Thank you for the update.

    Yes, my bad. I just realized how pointless the solution above is. Please edit the enfold/includes/helper-privacy.php file and look for this code around line 131.

    add_action( 'wp_head', array( $this, 'handler_wp_head_script' ), 1 );
    

    Comment it out or remove it completely, then add this code below.

    add_action( 'wp_footer', array( $this, 'handler_wp_head_script' ), 1 );
    

    Best regards,
    Ismael

    #1305234

    thanks Ismael for your support, this time it worked, when the theme is updated that file is overwritten?

    #1305264

    Hi,

    Yes, unfortunately, this will get overwritten on update. Unfortunately, we cannot find a way to override the current action hook that is attached to the privacy class in the functions.php file. This is also why we recommended the first solution.

    Why do you need the script in the footer anyway? It should work fine in the head tag and should not incur any performance overhead.

    Best regards,
    Ismael

    #1305278

    actually it is not for the overhead, i think it could have a negative impact on seo, i like clean code, with fewer scripts possible, or at least transfer the js in the footer

    #1305302

    I also preferred the first solution, but unfortunately it doesn’t work, I inserted your code in the function.php file of the child theme but to no avail, maybe if you can find another way to make that code stable even when updates are made it would be a lot better.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.