We often need to inject some custom scripts to our WordPress websites. From Google Alalytics 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

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

Click to enlarge
Click to enlarge
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.

Leave a Reply

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