Title: adding code to header.php
Last modified: January 10, 2022

---

# adding code to header.php

 *  Resolved [brucemacg](https://wordpress.org/support/users/brucemacg/)
 * (@brucemacg)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/adding-code-to-header-php/)
 * I would like to use your plugin if possible to add code to my header.php. I’ve
   searched around but cannot get this to work. I’m using Storefront theme, and 
   I do have a child theme.
 * I add this code at the very end of my functions.php to show rankmath breadcrumbs
   on my site (but not on the front page)
 * if (function_exists(‘rank_math_the_breadcrumbs’) && !is_front_page()) rank_math_the_breadcrumbs();?
   >
 * I tried this code on Snippets.
 * add_action( ‘wp_head’, function () { ?>
 * if (function_exists(‘rank_math_the_breadcrumbs’) && !is_front_page()) rank_math_the_breadcrumbs();?
   >
 * <?php } );
 * This doesn’t work…
 * I’d like to add the Google GTM tag to header.php.
 * Currently I have added this piece of code straight after the <body> in header.
   php
 * <?php if ( function_exists( ‘gtm4wp_the_gtm_tag’ ) ) { gtm4wp_the_gtm_tag(); }?
   >
 * I haven’t tried to add this yet, as I’m unsure how to test to ensure that it 
   works…
 * Can I use your plugin to add these 2 pieces or code, or do I need another. (or
   just to add the code as it is, in header.php. It works there..??
 * Regards, Bruce
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fadding-code-to-header-php%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/adding-code-to-header-php/#post-15621423)
 * Looks like you have some malformed PHP code in that breadcrumb function. Try 
   this instead:
 *     ```
       add_action( 'after_setup_theme', function () {
   
       	if ( function_exists( 'rank_math_the_breadcrumbs' ) && ! is_front_page() ) {
       		rank_math_the_breadcrumbs();
       	}
       } );
       ```
   
 * You should be able to add the Google GTM tag with `wp_body_open`, as long as 
   your theme supports it:
 *     ```
       add_action( 'wp_body_open', function () {
   
       	if ( function_exists( 'gtm4wp_the_gtm_tag' ) ) {
       		gtm4wp_the_gtm_tag();
       	}
       } );
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘adding code to header.php’ is closed to new replies.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * Last activity: [4 years, 1 month ago](https://wordpress.org/support/topic/adding-code-to-header-php/#post-15621423)
 * Status: resolved