'method_name', 'wp_head' => array( 'function_to_add' => 'render', 'priority' => 1, ), 'italystrap_before' => array( 'function_to_add' => 'render', 'priority' => 1, ), ); } /** * Plugin options settings. * * @var array */ private $options = null; private static $position = ''; /** * Init the constructor. * * @param array $argument Plugin options settings. */ function __construct( array $options = array() ) { $this->options = $options; // add_filter( 'body_class', array( $this, 'render_tag_manager' ), 10000, 2 ); } /** * Render * * @param string $value [description] * @return string [description] */ public function render() { if ( is_customize_preview() || is_preview() || is_admin() ) { return; } if ( empty( $this->options['google_tag_manager_id'] ) ) { return; } $current_filter = current_filter() === 'wp_head'; $file_name = $current_filter ? 'head' : 'body'; echo $this->get_view( $file_name ); } /** * Get the tag manager script * * @param string $value [description] * @return string [description] */ public function get_view( $file_name = '' ) { $id = $this->options['google_tag_manager_id']; ob_start(); require( 'views/tag-manager-' . $file_name . '.php' ); return ob_get_clean(); } /** * Google tag manager * @link http://www.tagmanageritalia.it/come-installare-google-tag-manager-tramite-wordpress/ * Filters the list of CSS body classes for the current post or page. * * @since 2.2.2 * * @param array $classes An array of body classes. * @param array $class An array of additional classes added to the body. */ public function render_tag_manager( $classes, $class ) { if ( is_customize_preview() || is_preview() || is_admin() ) { return; } if ( empty( $this->options['google_tag_manager_id'] ) ) { return; } $snippet = sprintf( '', esc_js( $this->options['google_tag_manager_id'] ) ); $classes[] = sprintf( '">%s