• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Adding Script to Header through Functions.php

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Adding Script to Header through Functions.php

This topic is: resolved
  • This topic has 4 replies, 2 voices, and was last updated 12 years, 3 months ago by sarahann.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • February 19, 2014 at 5:40 pm #91288
    sarahann
    Member

    HI,

    I need to add a script to the header.php but I don't want to do that in the framework for obvious reasons. I would normally do this through the CMS header section but the code needs to load earlier in the file than at the end as it is a mobile code and will otherwise load everything before it loads the script I am adding.

    I'd like to do so in the functions.php but I don't know PHP. Can someone please help me out with the proper code to insert a script into the top of the header?

    Thanks!

    February 19, 2014 at 9:20 pm #91320
    Brad Dalton
    Participant

    Is it dependant on jQuery or not?

    You can look in the functions file of many SP child themes and see how its done correctly.

    Here's the way it should be be done except for Google Analytics http://codex.wordpress.org/Function_Reference/wp_enqueue_script


    Tutorials for StudioPress Themes.

    February 20, 2014 at 11:53 am #91437
    sarahann
    Member

    Thanks Brad,

    It's Javascript for a mobile redirect:

    <script src="http://static.mobilewebsiteserver.com/redirect.js" type="text/javascript"></script>
    <script type="text/javascript">Mobile_redirect("http://m.yoururl.com");</script>

    It seems like the header hook only allows you to link into it right before the </head> tag. Is there a way to insert something right after the <head> tag?

    February 20, 2014 at 2:46 pm #91481
    Brad Dalton
    Participant

    Yes. If you check the genesis hooks, use the one which executes exactly where you want.

    The Genesis Simple Hooks plugin includes info about exactly where each hook executes in relation to HTML tags.


    Tutorials for StudioPress Themes.

    February 21, 2014 at 1:04 pm #91744
    sarahann
    Member

    Perfect, Thanks Brad! I found that the genesis_meta hook works for my purposes.

    Cheers,
    Sarah

  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble