Last active
September 3, 2022 10:40
-
-
Save endurtech/0e1b6f8918c10a3ca73465533426a173 to your computer and use it in GitHub Desktop.
Insert this code into the functions.php file within your WordPress child-theme to inject any custom code into the HEADER of your WordPress website.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Inserting a Script into WordPress Header | |
| // https://endurtech.com/insert-script-into-wordpress-header/ | |
| // wp_head action hook to inject a script | |
| add_action( 'wp_head', 'custom_header_scripts' ); | |
| function custom_header_scripts() | |
| { | |
| echo '<script>alert( "This is triggered from within the header of your website." );</script>'; | |
| } | |
| // Alternatively, you can stop and restart PHP processing to inject your code | |
| // which helps bypass potential issues with apostrophes or quotations | |
| add_action( 'wp_head', 'custom_header_scripts' ); | |
| function custom_header_scripts() | |
| { | |
| ?> | |
| <script>alert( "This is triggered from within the header of your website." );</script> | |
| <?php | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment