fbpx

How To Add Custom Scripts To WordPress Header And Footer Through Customizer

We often need to inject some custom scripts to our WordPress websites. From Google Analytics code to custom tweaks, it’s really handy to have the ability to insert some scripts which lacks in WordPress. Though there is a way to add additional CSS, you can’t really add any scripts without editing theme or plugin.

Using Plugin

You can add custom scripts to your WordPress websites using a plugin and perhaps it’s the best and safest way if you trust the plugin. When you don’t need the scripts, you can take off them and disable the plugin.

There are few plugins in WordPress repository but none of them using Customizer feature. So you need to add them from WordPress Dashboard, save script and check back the pages to test the functionality.  Since I often need to add some scripts to add interactivity or custom features, I felt it should use the Customizer so that it could be tested on the fly. So I built a fresh new plugin for this and released for free on the WordPress repository. You can check Custom Header Footer Scripts for Customizer.

How To Add Custom Scripts To WordPress Header And Footer Through Customizer 1
Download WordPress Plugin

Using this plugin, you can add multiple scripts to header or footer that might be Google Analytics, Facebook Like Box, YouTube Subscribe button, Pinterest integration and anything. So give it a try and let me know if you have any feedback. It’s also available on Github.

Some screenshots :

How To Add Custom Scripts To WordPress Header And Footer Through Customizer 2
Click to enlarge
How To Add Custom Scripts To WordPress Header And Footer Through Customizer 4
Click to enlarge
How To Add Custom Scripts To WordPress Header And Footer Through Customizer 6
Click to enlarge

Using Custom Code

If you want to get your hands dirty or want to add the functionality to your theme or plugin, here goes the necessary function to add this to either WordPress header or footer.

Add to WP HEADER

Add to WP Footer

You can add this to your Child Theme’s functions.php or within your theme or plugin.

Picture of Rupok

Rupok

CEO at WPDeveloper. I love to build beautiful & complex front-end and stuff on top of WordPress.

Share This Story

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Wait… Before You Leave

Enter 2025 with BIG savings & a boost to your business.

  • 00Days
  • 00Hours
  • 00Mins
  • 00Secs