Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #865640

    Stanley Tan
    Participant

    Hi, how can we add custom code to the <body> or <head> or before </body> section to the child theme?

    #865797

    Zeshan
    Member

    Hi Stanley,

    Thanks for writing in!

    You can insert the code right after the <body> tag using this code in your child theme’s functions.php file:

    
    // Adding Scripts Right After the <body> tag of the Site
    // =============================================================================
    
    function scripts_inside_body() { ?>
      <!-- Add your Code here -->
    <?php }
    
    add_action('x_before_site_begin', 'scripts_inside_body');
    

    If you want to insert it inside the <head> tag, use this code instead:

    // Adding Scripts inside the <head> tag of the Site
    // =============================================================================
    
    function scripts_inside_head() { ?>
      <!-- Add your Code here -->
    <?php }
    
    add_action('wp_head', 'scripts_inside_head');
    

    Thank you!