[Resolved] Adding script to footer area or footer widget

Home Forums Support [Resolved] Adding script to footer area or footer widget

Home Forums Support Adding script to footer area or footer widget

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

    Hi,
    want to add a little bit of code that goes in front of the /<head> tag in the footer. I already have some text in the footer bar and would like this to appear above it. It’s a GDPR notice and will disappear when user clicks OK.

    Is it best to put it into the footer window or as a widget in the footer?

    Read some posts/info and created and activated the plug-in. But it doesn’t appear in the front page.

    Have I missed something? Thanks, here’s the code:

    <?php if ( is_front_page() ) : ?>
    /*
    Plugin Name: WAC GDPR plug
    Plugin URI:
    Description:
    Version: 2020.1
    Author:
    Author URI:
    License:
    License URI:
    */
    <link rel=”stylesheet” type=”text/css” href=”//wpcc.io/lib/1.0.2/cookieconsent.min.css”/>

    <script src=”//wpcc.io/lib/1.0.2/cookieconsent.min.js”></script>
    <script>window.addEventListener(“load”, function(){window.wpcc.init({“border”:”thin”,”corners”:”small”,”colors”:{“popup”:{“background”:”#edeff5″,”text”:”#838391″,”border”:”#edeff5″},”button”:{“background”:”#0073ff”,”text”:”#ffffff”}},”content”:{“message”:”This website uses cookies (including 3rd party: Google analytics + Facebook links) to help improve website function and user experience. Our Privacy Policy explains how and why.”,”href”:”https://www.warlinghamarchers.uk/cookie-policy&#8221;,”link”:”See the Privacy Policy”}
    })});
    </script>
    <?php endif; ?>

    #1148367
    David
    Staff
    Customer Support

    Hi there,

    you can use the Hook Element to add the script:

    https://docs.generatepress.com/article/hooks-element-overview/

    The WP_footer hook is in the footer.

    #1149114
    Paul

    Thanks David,
    read all that, added element with the code BUT where do I put the code listed under Hooks/Usage here

    PS do I need to create a child theme to preserve these elements?

    Paul

    #1149181
    David
    Staff
    Customer Support

    No child theme required if using the Hook Element.
    Simply:
    Appearance > Elements > New –> Hook.
    Add your code to the content text area.
    Select the WP_Head hook and check Execute PHP.
    Then on the Display Rules tab – set the Location where you want the script to fire e.g Entire Site

    #1149196
    Paul

    Thanks David,
    checked live site and it worked – sort of. I used the hook ‘generate before footer’ and thought it might stick above the footer if I scrolled up/down the page – instead it moves up/down screen with me.
    I’m not too bothered by that but just wondered, for future reference, is there a hook that would stick it to the footer.
    Paul

    #1149222
    David
    Staff
    Customer Support

    In this instance the hook you choose has no baring on the position of the cookie notice.
    What the hook is doing is simply adding some code that gets executed by the browser. It is the code that is responsible for how and where the cookie notice is displayed.

    I am not sure where the code comes from – but maybe the offer some other ‘styling’ options.

    #1149516
    Paul

    That’s fine. Thanks David

    #1149840
    David
    Staff
    Customer Support

    You’re welcome

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.