Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
uc-remarketing/uc-remarketing.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
61 lines (47 sloc)
1.66 KB
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
<?php | |
/* | |
Plugin Name: UC Google Remarketing | |
Author: Dessalegne Chekol | |
Version: 1.0 | |
Description: Adds Google AdWords Remarketing code on all pages | |
*/ | |
add_action('wp_footer', 'google_script'); | |
function google_script() | |
{ | |
$regex = '/^\d+$/'; | |
if ( preg_match($regex, get_option( 'my_google_id', '' ))&& (get_option( 'my_google_id', '' )!=null)) { | |
$x=get_option( 'my_google_id', '' ); | |
?> | |
<script type="text/javascript"> | |
/* <![CDATA[ */ | |
var google_conversion_id = <?php echo $x;?>; | |
var google_custom_params = window.google_tag_params; | |
var google_remarketing_only = true; | |
/* ]]> */ | |
</script> | |
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js"> | |
</script> | |
<noscript> | |
<div style="display:inline;"> | |
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/<?php echo $x;?>/?value=0&guid=ON&script=0"/> | |
</div> | |
</noscript> | |
<?php | |
} | |
} | |
function register_fields() | |
{ | |
register_setting('general', 'my_google_id', 'esc_attr'); | |
add_settings_field('my_google_id', '<label for="my_google_id">'.__('Google Remarketing ID' , 'my_google_id' ).'</label>' , 'print_custom_field', 'general'); | |
} | |
function print_custom_field() | |
{ | |
$regex = '/^\d+$/'; | |
if ( preg_match($regex, get_option( 'my_google_id', '' )) ) { | |
$value = get_option( 'my_google_id', '' ); | |
echo '<input type="text" id="my_google_id" name="my_google_id" value="' . esc_attr( $value ) . '" />'; | |
} | |
else | |
echo '<input type="text" id="my_google_id" name="my_google_id" value="" />'; | |
} | |
add_filter('admin_init', 'register_fields'); |