Title: Filter Request
Last modified: August 22, 2016

---

# Filter Request

 *  Resolved [Nelio Software](https://wordpress.org/support/users/nelio/)
 * (@nelio)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/filter-request-2/)
 * Hi! This is my problem: the code contained inside the `script` tag returned by`
   gtm4wp_get_the_gtm_tag` is automatically executed when the browser gets there.
   I know this is the default behavior (that’s Google’s code). However, I’d like
   to call that code when I want. In order to do so, I thought I could simply surround
   that script with a named function, and then call that function when I need to.
 * Could you please update the plugin and add a new filter there? This way, right
   before the variable `$_gtm_tag` is returned, one can hook edit the return value:
 *     ```
       - return $_gtm_tag;
       + return apply_filters( 'gtm4wp_get_the_gtm_tag', $_gtm_tag );
       ```
   
 * Then, I could do something like this:
 *     ```
       add_filter( 'gtm4wp_get_the_gtm_tag', 'nelio_tweak_gtm_tag' );
       function nelio_tweak_gtm_tag( $script ) {
         $script = str_replace(
           '<script>', '<script>nelioWrapperFunc() {', $script
         );
         $script = str_replace(
           '</script>', '}</script>', $script
         );
         return $script;
       }
       ```
   
 * Please, let me know if this is possible. Thank you very much for your time and
   help!
 * [https://wordpress.org/plugins/duracelltomi-google-tag-manager/](https://wordpress.org/plugins/duracelltomi-google-tag-manager/)

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

 *  Plugin Author [Thomas Geiger](https://wordpress.org/support/users/duracelltomi/)
 * (@duracelltomi)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/filter-request-2/#post-5351693)
 * Hi,
 * To be honest (as always) I do not know what the use case is in your situation.
   According to the Google docs this tag needs to be placed after the opening body
   tag therefore wrapping it using a function call could cause unexpected behavior.
 * But you know what? Maybe this is just not by business 🙂
    I added this filter
   to the development version, the next release will contain it 🙂
 * Cheers,
    Thomas
 *  Thread Starter [Nelio Software](https://wordpress.org/support/users/nelio/)
 * (@nelio)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/filter-request-2/#post-5351709)
 * Thanks for your prompt response! That’s great news!
 *  Thread Starter [Nelio Software](https://wordpress.org/support/users/nelio/)
 * (@nelio)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/filter-request-2/#post-5351971)
 * Hi,
 * I see you updated the plugin, but the filter I requested is not there yet. Is
   there any option for me to wrap GTM’s function as I originally requested?
 * Thanks!
 *  Plugin Author [Thomas Geiger](https://wordpress.org/support/users/duracelltomi/)
 * (@duracelltomi)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/filter-request-2/#post-5351972)
 * Hi,
 * There was not any new release, I just updated that the plugin is compatible with
   WP 4.1
 * I am currently investigating an issue regarding woocommerce integration, this
   is the reason why it takes so long for the new release.
 * Thomas
 *  Thread Starter [Nelio Software](https://wordpress.org/support/users/nelio/)
 * (@nelio)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/filter-request-2/#post-5351973)
 * Oh, I see. Thanks for the answer! Any clue on when it’ll be ready?
 *  Plugin Author [Thomas Geiger](https://wordpress.org/support/users/duracelltomi/)
 * (@duracelltomi)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/filter-request-2/#post-5351974)
 * If you do not mind I do not intend to pin another date. I know it is not the 
   answer you want to here but: as soon as possible 🙂
 *  Thread Starter [Nelio Software](https://wordpress.org/support/users/nelio/)
 * (@nelio)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/filter-request-2/#post-5351975)
 * Sure, that’s fine! No pressure 😉

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

The topic ‘Filter Request’ is closed to new replies.

 * ![](https://ps.w.org/duracelltomi-google-tag-manager/assets/icon-256x256.png?
   rev=1708451)
 * [GTM4WP - A Google Tag Manager (GTM) plugin for WordPress](https://wordpress.org/plugins/duracelltomi-google-tag-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/duracelltomi-google-tag-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/duracelltomi-google-tag-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/duracelltomi-google-tag-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/duracelltomi-google-tag-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/duracelltomi-google-tag-manager/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [Nelio Software](https://wordpress.org/support/users/nelio/)
 * Last activity: [11 years, 3 months ago](https://wordpress.org/support/topic/filter-request-2/#post-5351975)
 * Status: resolved