Code in the header with a child theme?

  • Ricardo

    #2253

    I would like to add a piece of code to my header:

    <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>

    But, of course, every time I would update the theme I would have to add the code manually again. Is there a way to implement the code somewhere (child theme maybe?) so that it would also be there after an update?

    Mod

    Kenneth John Odle

    #19534

    The best way is to use an action in your functions.php file of your child theme. and attach it to the “wp_head()” action hook.

    Ricardo

    #19535

    I am going to ask you for some more help on this one (Googled it first of course). How do you attach it to the action hook?

    Josh

    #19536

    Can you just create an action hook in the header.php, try the graphene_container_before.

    I don’t think the script will show anything, and I haven’t tested this, but give it a try and see what happens.

    I’m curious 🙂

    Ricardo

    #19537

    That actually works! Thanks 🙂

    (Because my buttons counter still read mysterious numbers, I chose to add the 3 buttons myself without a counter)

    Josh

    #19538

    Awesome. Great to know.

    Yeah, I’ve seen a lot of people having issues with the counters using various social sharing.

    Glad you got it working!

    ALSO: This might be a good place to store any scripts in the future that require being placed in the header. I know various add-ons require a script code in the header. Maybe this could be used like a “script tank”??

    Thanks for testing!

    Ricardo

    #19539

    I was thinking exactly the same. It’s really frustrating when loose the code before updating and you have to search for it again 😉

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

You must be logged in to reply to this topic.