Tagged: 

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #453073

    Hi,
    I have the need to enter a code (scripts privacy legislation) before the tag </head> of all pages.
    At the time I put this code in header.php
    It works very well, but I want to avoid changing the theme Enfold, I would put this code in the file functions.php of the my child theme.
    You can help me?
    Thanks

    • This topic was modified 9 years, 5 months ago by macrunner.
    #453581

    Hi macrunner!

    You can use this in functions.php to hook to wp_head:

    function add_custom_code(){
    //YOUR CODE HERE
    }
    add_action('wp_head', 'add_custom_code');

    Cheers!
    Rikard

    #453600

    Hi Rikard,
    unfortunately it does not work, I get a blank page.
    Maybe because my code is complex?
    Here is the code that I use:

    <link rel="stylesheet" type="text/css" href="http://www.mydomain.com/privacy/main.css"/>
    <script type="text/javascript" src="http://www.mydomain.com/privacy/cookieplugin.js"></script>
    <script type="text/javascript">
    // <![CDATA[
    cc.initialise({
    	cookies: {
    		social: {},
    		necessary: {}
    	},
    settings: {
    	bannerPosition: "push",
    	disableallsites: true
    },
    	strings: {
    socialDefaultDescription: 'Facebook, Twitter and other social websites need to know who you are to work properly.',
    necessaryDefaultTitle: 'Necessary',
    privacySettings: 'Privacy settings',
    savePreference: 'Save settings',
    allowCookiesImplicit: 'Close',
    backToSiteSettings: 'Back Settings'
    	}
    });
    // ]]>

    Thanks!

    #453912

    Hey!

    Please change the code to following one

    function add_custom_code(){
    ?>
    //YOUR CODE HERE
    <?php
    }
    add_action('wp_head', 'add_custom_code');

    Best regards,
    Yigit

    #454260

    Hi Ygit,
    It works great
    thank you

    #454545

    Hi!

    Great, glad we could help :)

    Regards,
    Rikard

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Code before tag /head in child theme’ is closed to new replies.