Last active
August 29, 2015 14:19
-
-
Save jonrivers/eb486bad7e3bc1c83a40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sanitization | |
* @author Bill Erickson (http://www.billerickson.net/) | |
* @link http://www.billerickson.net/genesis-theme-options/ | |
* | |
*/ | |
function genesis_simple_gtm_sanitization_filters() { | |
genesis_add_option_filter( 'requires_unfiltered_html', GENESIS_SETTINGS_FIELD, | |
array( | |
'genesis_simple_gtm_gtmcode', | |
'genesis_simple_gtm_thankyoucode', | |
) ); | |
} | |
add_action( 'genesis_settings_sanitizer_init', 'genesis_simple_gtm_sanitization_filters' ); | |
/** | |
* Register Metabox | |
* @author Bill Erickson (http://www.billerickson.net/) | |
* @link http://www.billerickson.net/genesis-theme-options/ | |
* | |
* @param string $_genesis_theme_settings_pagehook | |
*/ | |
function genesis_simple_gtm_register_settings_box( $_genesis_theme_settings_pagehook ) { | |
add_meta_box('cg-theme-settings', 'Genesis Simple Tag Manager', 'genesis_simple_gtm_settings_box', $_genesis_theme_settings_pagehook, 'main', 'high'); | |
} | |
add_action('genesis_theme_settings_metaboxes', 'genesis_simple_gtm_register_settings_box'); | |
/** | |
* Create Metabox | |
* @author Bill Erickson | |
* @link http://www.billerickson.net/genesis-theme-options/ | |
* | |
*/ | |
function genesis_simple_gtm_settings_box() { | |
?> | |
<label for="<?php $this->field_id( 'genesis_simple_gtm_gtmcode' ); ?>"><?php printf( __( 'Enter scripts or code you would like output to %s:', 'genesis' ), genesis_code( 'wp_head()' ) ); ?></label> | |
<textarea name="<?php $this->field_name( 'genesis_simple_gtm_gtmcode' ); ?>" class="large-text" id="<?php $this->field_id( 'genesis_simple_gtm_gtmcode' ); ?>" cols="78" rows="8"><?php echo esc_textarea( $this->get_field_value( 'genesis_simple_gtm_gtmcode' ) ); ?></textarea> | |
<p><span class="description"><?php printf( __( 'The %1$s hook executes immediately before the closing %2$s tag in the document source.', 'genesis' ), genesis_code( 'wp_head()' ), genesis_code( '</head>' ) ); ?></span></p> | |
<hr class="div" /> | |
<label for="<?php $this->field_id( 'genesis_simple_gtm_thankyoucode' ); ?>"><?php printf( __( 'Enter scripts or code you would like output to %s:', 'genesis' ), genesis_code( 'wp_head()' ) ); ?></label> | |
<textarea name="<?php $this->field_name( 'genesis_simple_gtm_thankyoucode' ); ?>" class="large-text" id="<?php $this->field_id( 'genesis_simple_gtm_thankyoucode' ); ?>" cols="78" rows="8"><?php echo esc_textarea( $this->get_field_value( 'genesis_simple_gtm_thankyoucode' ) ); ?></textarea> | |
<p><span class="description"><?php printf( __( 'The %1$s hook executes immediately before the closing %2$s tag in the document source.', 'genesis' ), genesis_code( 'wp_head()' ), genesis_code( '</head>' ) ); ?></span></p> | |
<hr class="div" /> | |
<?php | |
} | |
//* Add Google Tag Manager before closing body tag | |
add_action('genesis_before', 'genesis_simple_gtm_output_gtmcode'); | |
function genesis_simple_gtm_output_gtmcode() { | |
$gtmcode = esc_attr( genesis_get_option('genesis_simple_gtm_gtmcode') ); | |
print $gtmcode; | |
} | |
//* Add Google Conversion Tracking before closing body tag on page with 'thanks' as slug | |
add_action('genesis_after', 'genesis_simple_gtm_output_gtmcode'); | |
function genesis_simple_gtm_output_gtmcode() { | |
$gtmthankyou = esc_attr( genesis_get_option('genesis_simple_gtm_thankyoucode') ); | |
if_is_page( 'thanks') { | |
print $gtmthankyou; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment