WordPress: How to Inject Code Into Header and Footer Through Functions.php Child File

Keeping things as simple as possible here’s a way to add code into the header and footer of all your pages and posts in WordPress.
Add the following lines of code in your functions.php file.

Example 1

Note: As you can see “wp_footer” is a function that’s already defined in your WordPress installation and “name_of_your_function” is a random name that I’ve chosen to define a function to print the words “hello world” (I could’ve just as easily named it “nameofyourfunction”) in which case it would look like this:

Example 2

To add things to your header you simply use “wp_head” instead of “wp_footer” like so:



Post Author: Chad

A Nobody Just Trying to Figure Things Out.

Leave a Reply

Your email address will not be published.