Tagged: 

Viewing 15 posts - 1 through 15 (of 15 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.

    #1305535

    Hi,

    i think it could have a negative impact on seo

    Why would it have a negative impact on SEO? It is a very a small script which should not affect the actual content of the site.

    Best regards,
    Ismael

    #1305567

    because I believe that the structure of an html site should be clean especially the part that concerns the meta tags with as few scripts as possible, and not grafted between the meta with raw code, for me they should all be inserted in the footer I don’t say it I have it read in textbooks. In any case it is not a criticism, on the contrary I really like the enfold theme I know that it is one of the best themes around, even if in my opinion some things could still be improved.

    #1306002

    Hi,

    Crawlers should be smart enough to ignore scripts that are not directly related to the content or at least assign priority on how they should be assessed, so having this small script within the head tag will not affect how search engines crawl the site.

    You may need to keep the modification for now if you really need to move it to the footer.

    Best regards,
    Ismael

    #1306511

    ok tanks

    #1306611

    Hi,

    Did you need additional help with this topic or shall we close?

    Best regards,
    Jordan Shannon

    #1306765

    yes for now it’s okay thanks.

    #1307025

    Hi,

    If you need additional help, please let us know here in the forums.

    Best regards,
    Jordan Shannon

Viewing 15 posts - 1 through 15 (of 15 total)
  • The topic ‘how can i move the js script avia_cookie_check_sessionStorage () in the footer?’ is closed to new replies.