Get inside access to design tips from a pro! Subscribe to Design to Dollars

GeneratePress

How to Add Scripts to Your Header in GeneratePress

Adam Wright

by Adam Wright

If you’re using the GeneratePress theme and need to add script tags to your header—whether it’s for Google Analytics, Facebook Pixel, or any other code—GeneratePress has a built-in feature called Elements that makes this process quick and easy. Here’s how you can do it:

Step 1: Access the Elements Feature

  1. From your WordPress dashboard, navigate to Appearance and then click on Elements under the GeneratePress section.
  2. This is where you’ll manage your hooks for adding scripts and other custom code.

Step 2: Create a New Hook Element

  1. Click on Add New Element and select Hook from the options.
  2. Click Create to start creating your new hook.

Step 3: Name and Add Your Script

  1. Name your hook appropriately—such as “Google Analytics Code”—so you can easily identify it later.
  2. In the Code box, paste the script code you need to add. This could be any kind of tracking code or custom script that requires placement in your header or another part of your site.

Step 4: Choose the Hook Location

  1. Scroll down to the Hook section. Here, you’ll choose where to place your code.
    • WP head: This is where you’ll typically insert codes that need to be in the header, such as Google Analytics.
    • WP body open: If the instructions for your script specify that it should be placed at the beginning of the body tag, select this option.
    • Footer: For scripts that should load at the bottom of the page, select a footer-related hook.
  2. Select the appropriate hook based on your script’s requirements.

Step 5: Set Display Rules

  1. Under Display Rules, decide where you want the script to run.
    • Entire Site: This is common for global scripts like Google Analytics.
    • Specific Pages: If you only need the script on certain pages, you can specify that here.
    • Exclude Pages: You can also exclude pages if there are areas of your site where the script shouldn’t run, such as excluding a tag from your blog posts.
  2. You can also control which users see this script, though typically, you’ll leave this as All Users.

Step 6: Publish and Manage Your Scripts

  1. Once everything is set, click Publish to activate the script on your site.
  2. To manage your scripts, return to the Elements overview page. Here, you’ll see a list of all your elements.
    • If you need to disable a script temporarily, simply use the Quick Edit option and change its status to Draft. This will remove the code from your site without permanently deleting it.

Final Tips

  • Label Your Elements Clearly: Always name your hooks clearly, like “Google Analytics Code” or “Facebook Pixel Code,” so you can easily manage and identify them later.
  • Disable with Ease: You can turn individual scripts on or off without affecting others, giving you fine control over your site’s functionality.

Using the Elements feature in GeneratePress makes adding and managing scripts on your site straightforward, helping you keep everything organized and easily accessible for future changes.

Subscribe

Follow My YouTube Channel for More Tutorials

Subscribe to Channel
Adam Wright

About the Author

Adam Wright

Adam is a California native, now living in Middle Tennessee. A long-time creative at heart, his passion for design and growing his small business, AWD, is always evident. When he's not writing code or sketching logos, he enjoys spending time with family, playing basketball, or watching just about any motorsports. Find him on LinkedIn.