Title: insert code in header and body
Last modified: April 6, 2024

---

# insert code in header and body

 *  [stefanocps](https://wordpress.org/support/users/stefanocps/)
 * (@stefanocps)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/insert-code-in-header-and-body/)
 * HYello i need to insert code in the head section and iht body section (tracking
   google code and similar)
 * I don’t want to use a plugin and i want to write straigh tin thephp file sof 
   my theme
 * I have created a child theme…but don’t know how to go on
 * I have tried different tutorial form google , iset codes infunction-php but the
   site break down
 * Any help?thanks

Viewing 15 replies - 1 through 15 (of 24 total)

1 [2](https://wordpress.org/support/topic/insert-code-in-header-and-body/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/insert-code-in-header-and-body/page/2/?output_format=md)

 *  [Benjamin Zekavica](https://wordpress.org/support/users/benjamin_zekavica/)
 * (@benjamin_zekavica)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/insert-code-in-header-and-body/#post-17556425)
 * Hallo [@stefanocps](https://wordpress.org/support/users/stefanocps/),
 * you can use the hooks: **wp_head** and **wp_footer** and .`**wp_body_open**`
   
   You can add this Code to your functions.php in your Child Theme. For example:**
   Header**
 * `add_action('wp_head', function() {
    // Your HTML Code / Example?> <script type
   ="text/javascript" src="https://wordpress.org/your-files.js"></script><?php });
 * **Footer**
 * `add_action('wp_footer', function() {
   // Your HTML Code / Example?><script type
   ="text/javascript" src="https://wordpress.org/your-files.js"></script><?php});
 * **Body**
 * `add_action( 'wp_body_open', function() {`
    `?>` `<script>// Your script code
   here</script><``?php});`
    -  This reply was modified 2 years, 2 months ago by [Benjamin Zekavica](https://wordpress.org/support/users/benjamin_zekavica/).
    -  This reply was modified 2 years, 2 months ago by [Benjamin Zekavica](https://wordpress.org/support/users/benjamin_zekavica/).
 *  Thread Starter [stefanocps](https://wordpress.org/support/users/stefanocps/)
 * (@stefanocps)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/insert-code-in-header-and-body/#post-17556429)
 * i tried the code for body and get error
 * i have added in the child function.php
 * i think it is something related to hte <?php at the end and to the <? at the 
   beginning?
 * ythe error is either with heder and body
    -  This reply was modified 2 years, 2 months ago by [stefanocps](https://wordpress.org/support/users/stefanocps/).
    -  This reply was modified 2 years, 2 months ago by [stefanocps](https://wordpress.org/support/users/stefanocps/).
 *  [Benjamin Zekavica](https://wordpress.org/support/users/benjamin_zekavica/)
 * (@benjamin_zekavica)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/insert-code-in-header-and-body/#post-17556439)
 * [@stefanocps](https://wordpress.org/support/users/stefanocps/) Do you can add
   you code from the functions.php here ? Than I can help you 🙂 
   Make sure that
   the beginning of the functions.php is beginning with` <?php` and than to add 
   and customize your Code.
 *  Thread Starter [stefanocps](https://wordpress.org/support/users/stefanocps/)
 * (@stefanocps)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/insert-code-in-header-and-body/#post-17556452)
 * this is the funcion.php in child theme, where i am adding the code
 *     ```wp-block-code
       <?php
   
       // Exit if accessed directly
   
       if ( !defined( 'ABSPATH' ) ) exit;
   
       // BEGIN ENQUEUE PARENT ACTION
   
       // AUTO GENERATED - Do not modify or remove comment markers above or below:
   
       if ( !function_exists( 'chld_thm_cfg_locale_css' ) ):
   
           function chld_thm_cfg_locale_css( $uri ){
   
               if ( empty( $uri ) && is_rtl() && file_exists( get_template_directory() . '/rtl.css' ) )
   
                   $uri = get_template_directory_uri() . '/rtl.css';
   
               return $uri;
   
           }
   
       endif;
   
       add_filter( 'locale_stylesheet_uri', 'chld_thm_cfg_locale_css' );
   
       if ( !function_exists( 'child_theme_configurator_css' ) ):
   
           function child_theme_configurator_css() {
   
               wp_enqueue_style( 'chld_thm_cfg_child', trailingslashit( get_stylesheet_directory_uri() ) . 'style.css', array( 'hello-elementor','hello-elementor','hello-elementor-theme-style','hello-elementor-header-footer' ) );
   
           }
   
       endif;
   
       add_action( 'wp_enqueue_scripts', 'child_theme_configurator_css', 10 );
   
       // END ENQUEUE PARENT ACTION
       ```
   
 *  [Benjamin Zekavica](https://wordpress.org/support/users/benjamin_zekavica/)
 * (@benjamin_zekavica)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/insert-code-in-header-and-body/#post-17556466)
 * [@stefanocps](https://wordpress.org/support/users/stefanocps/) Try this 🙂 In
   the line: if ( empty( $uri ) && is_rtl() && file_exists( get_template_directory().‘/
   rtl.css’ ) ) { 
   Was mission the beginning and ending PHP Tags.
 *     ```wp-block-code
       <?php
   
       // Exit if accessed directly
   
       if ( !defined( 'ABSPATH' ) ) exit;
   
       // BEGIN ENQUEUE PARENT ACTION
   
       // AUTO GENERATED - Do not modify or remove comment markers above or below:
   
       if ( !function_exists( 'chld_thm_cfg_locale_css' ) ) {
   
           function chld_thm_cfg_locale_css( $uri ){
   
               if ( empty( $uri ) && is_rtl() && file_exists( get_template_directory() . '/rtl.css' ) ) {
   
           $uri = get_template_directory_uri() . '/rtl.css';
   
               }
   
              return $uri;
           }
   
       }
       add_filter( 'locale_stylesheet_uri', 'chld_thm_cfg_locale_css' );
   
       if ( !function_exists( 'child_theme_configurator_css' ) ) {
   
          function child_theme_configurator_css() {
   
               wp_enqueue_style( 'chld_thm_cfg_child', trailingslashit( get_stylesheet_directory_uri() ) . 'style.css', array( 'hello-elementor','hello-elementor','hello-elementor-theme-style','hello-elementor-header-footer' ) );
   
           }
   
       }
       add_action( 'wp_enqueue_scripts', 'child_theme_configurator_css', 10 );
   
       // END ENQUEUE PARENT ACTION
   
       // ======== ADD YOUR CODE HERE (FOR EXAMPLE) ======== 
       add_action('wp_head', function() {
       // Your HTML Code / Example
       ?>
       <script type="text/javascript" src="https://wordpress.org/your-files.js"></script>
       <?php
       });
       ```
   
 *  Thread Starter [stefanocps](https://wordpress.org/support/users/stefanocps/)
 * (@stefanocps)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/insert-code-in-header-and-body/#post-17556473)
 * i copied just this code to the function.php (did not add any script yet and i
   get again error
 * without the code you wrote it works
    -  This reply was modified 2 years, 2 months ago by [stefanocps](https://wordpress.org/support/users/stefanocps/).
 *  [Benjamin Zekavica](https://wordpress.org/support/users/benjamin_zekavica/)
 * (@benjamin_zekavica)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/insert-code-in-header-and-body/#post-17556490)
 * Do you can send me the error message or copy it from the debug.log if it’s active.
   Which parent theme you use ?
 *  Thread Starter [stefanocps](https://wordpress.org/support/users/stefanocps/)
 * (@stefanocps)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/insert-code-in-header-and-body/#post-17556495)
 * hello elementor
 * don t know where to get th elog
 *  [Benjamin Zekavica](https://wordpress.org/support/users/benjamin_zekavica/)
 * (@benjamin_zekavica)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/insert-code-in-header-and-body/#post-17556526)
 * Ok, in the Pro Version of Elementor you can add Custom Header / Footer Code inside
   the settings.
 * The debug.log you can find under /wp-content/debug.log
   See this documentation:
   [https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/](https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/)
    -  This reply was modified 2 years, 2 months ago by [Benjamin Zekavica](https://wordpress.org/support/users/benjamin_zekavica/).
 *  Thread Starter [stefanocps](https://wordpress.org/support/users/stefanocps/)
 * (@stefanocps)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/insert-code-in-header-and-body/#post-17556542)
 * but i don t have tge pro version
 *  [Benjamin Zekavica](https://wordpress.org/support/users/benjamin_zekavica/)
 * (@benjamin_zekavica)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/insert-code-in-header-and-body/#post-17556544)
 * That’s no problem 🙂 The debug.log is one of the part of WordPress.
 * The Pro Version allows you to add code to WP Head and Footer from the Backend.
   But first I need to see the debug.log or the error message. Than I can help you.
 *  Thread Starter [stefanocps](https://wordpress.org/support/users/stefanocps/)
 * (@stefanocps)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/insert-code-in-header-and-body/#post-17556558)
 * please help me
 * i have added this in wp-config.php
 * // Enable Debug logging to the /wp-content/debug.log file
 * define( ‘WP_DEBUG_LOG’, true );
 * but don t get any log
    -  This reply was modified 2 years, 2 months ago by [stefanocps](https://wordpress.org/support/users/stefanocps/).
    -  This reply was modified 2 years, 2 months ago by [stefanocps](https://wordpress.org/support/users/stefanocps/).
 *  Thread Starter [stefanocps](https://wordpress.org/support/users/stefanocps/)
 * (@stefanocps)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/insert-code-in-header-and-body/#post-17556570)
 * i got this
 * **Parse error**: syntax error, unexpected token “<” in **/home/greenartcoin/domains/
   greenartcoin.eu/public_html/wp-content/themes/hello-elementor-child/functions.
   php** on line **42**
 *  [Benjamin Zekavica](https://wordpress.org/support/users/benjamin_zekavica/)
 * (@benjamin_zekavica)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/insert-code-in-header-and-body/#post-17556572)
 * Ok but where you saw the error after you added the code in the functions.php?
 *  Thread Starter [stefanocps](https://wordpress.org/support/users/stefanocps/)
 * (@stefanocps)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/insert-code-in-header-and-body/#post-17556582)
 * this if i only leave the plain code you gave me(no script)
 * **Warning**: Constant WP_DEBUG_LOG already defined in **/home/greenartcoin/domains/
   greenartcoin.eu/public_html/wp-config.php** on line **97**
 * **Deprecated**: ltrim(): Passing null to parameter #1 ($string) of type string
   is deprecated in **/home/greenartcoin/domains/greenartcoin.eu/public_html/wp-
   includes/formatting.php** on line **4494**

Viewing 15 replies - 1 through 15 (of 24 total)

1 [2](https://wordpress.org/support/topic/insert-code-in-header-and-body/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/insert-code-in-header-and-body/page/2/?output_format=md)

The topic ‘insert code in header and body’ is closed to new replies.

 * In: [Installing WordPress](https://wordpress.org/support/forum/installation/)
 * 24 replies
 * 3 participants
 * Last reply from: [Sumit Singh](https://wordpress.org/support/users/sumitsingh/)
 * Last activity: [2 years ago](https://wordpress.org/support/topic/insert-code-in-header-and-body/page/2/#post-17766890)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
