Title: Adding PHP Snippet to Template
Last modified: June 20, 2020

---

# Adding PHP Snippet to Template

 *  Resolved [jcpacelli](https://wordpress.org/support/users/jcpacelli/)
 * (@jcpacelli)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/adding-php-snippet-to-template/)
 * i see that i can add my GTM code to the blank-slate-template.php file in the 
   plugins folder but can i override this template file so i dont need to re-input
   the code if/when the Blank Slate plugin updates?
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fadding-php-snippet-to-template%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [Micah Wood](https://wordpress.org/support/users/wpscholar/)
 * (@wpscholar)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/adding-php-snippet-to-template/#post-13013535)
 * [@jcpacelli](https://wordpress.org/support/users/jcpacelli/) As a best practice,
   you shouldn’t hardcode your Google Tag Manager code into your theme or other 
   page templates. Instead, I’d recommend installing the Google Site Kit plugin (
   [https://wordpress.org/plugins/google-site-kit/](https://wordpress.org/plugins/google-site-kit/))
   and configuring Google Tag Manager through that. This will allow your code to
   be automatically applied to any WordPress theme or page template.
 *  Thread Starter [jcpacelli](https://wordpress.org/support/users/jcpacelli/)
 * (@jcpacelli)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/adding-php-snippet-to-template/#post-13013565)
 * Google Site Kit has its limitations as well so i have stopped using it. I have
   not seen that hardcoding the GTM is against best practices. I believe Site Kit
   is fairly new (< 1 year old?) and from what I have seen is best used for a brief,
   yet consolidated, view of site data.
 *  Plugin Author [Micah Wood](https://wordpress.org/support/users/wpscholar/)
 * (@wpscholar)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/adding-php-snippet-to-template/#post-13013610)
 * [@jcpacelli](https://wordpress.org/support/users/jcpacelli/) The issue with hardcoding
   is that if you edit a third-party theme directly, then those changes are lost
   the next time the theme is updated. If you hardcode in a child theme, then your
   GTM code is lost if you ever change themes. This is why utilizing a plugin for
   this is ideal. Plugins can hook into WordPress and properly load your GTM code
   in a variety of contexts.
 * While The Site Kit plugin is fairly new, it is maintained by the Google team 
   directly. It can display some site data/stats in the WordPress admin area, but
   its key function is to actually output Google Analytics and/or Google Tag Manager
   code for data collection.
    -  This reply was modified 5 years, 11 months ago by [Micah Wood](https://wordpress.org/support/users/wpscholar/).
 *  Thread Starter [jcpacelli](https://wordpress.org/support/users/jcpacelli/)
 * (@jcpacelli)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/adding-php-snippet-to-template/#post-13013624)
 * Thank you but I know what I am doing regarding my theme and plugin setup. I know
   what happens if I change themes or update plugins. I know what a child theme 
   is used for and how they work and I am not installing Site Kit again.
 * Your first sentence is why I opening this thread to begin with because I am fully
   aware of what happens when a plugin (or theme) is updated. I can edit the blank
   slate template every time it is updated as a last resort.
 * I am wondering if it is possible with your plugin to override that template like
   you can with WooCommerce, for example. Duplicating the PHP file and placing it
   in my child theme (which I know will be replaced if I change themes, which I 
   have no plans to do in the foreseeable future) in the directory of /childtheme/
   blank-slate/ does not override the plugin’s default file.
 *  Thread Starter [jcpacelli](https://wordpress.org/support/users/jcpacelli/)
 * (@jcpacelli)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/adding-php-snippet-to-template/#post-13044024)
 * I am still curious if this is possible with your plugin.
 *  Plugin Author [Micah Wood](https://wordpress.org/support/users/wpscholar/)
 * (@wpscholar)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/adding-php-snippet-to-template/#post-13044112)
 * [@jcpacelli](https://wordpress.org/support/users/jcpacelli/) At the moment, there
   is no way to just drop a file in a theme and have it override the existing templates
   in the plugin. However, there is a `blank_slate_templates` filter that you can
   use to accomplish the same thing.
 * [https://plugins.trac.wordpress.org/browser/blank-slate/tags/1.1.5/functions.php#L65](https://plugins.trac.wordpress.org/browser/blank-slate/tags/1.1.5/functions.php#L65)

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Adding PHP Snippet to Template’ is closed to new replies.

 * ![](https://ps.w.org/blank-slate/assets/icon-256x256.png?rev=1654426)
 * [Blank Slate](https://wordpress.org/plugins/blank-slate/)
 * [Support Threads](https://wordpress.org/support/plugin/blank-slate/)
 * [Active Topics](https://wordpress.org/support/plugin/blank-slate/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/blank-slate/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/blank-slate/reviews/)

## Tags

 * [gtm](https://wordpress.org/support/topic-tag/gtm/)
 * [header](https://wordpress.org/support/topic-tag/header/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [snippet](https://wordpress.org/support/topic-tag/snippet/)
 * [tag](https://wordpress.org/support/topic-tag/tag/)
 * [template](https://wordpress.org/support/topic-tag/template/)

 * 6 replies
 * 2 participants
 * Last reply from: [Micah Wood](https://wordpress.org/support/users/wpscholar/)
 * Last activity: [5 years, 11 months ago](https://wordpress.org/support/topic/adding-php-snippet-to-template/#post-13044112)
 * Status: resolved