I don't want to execute the script if the device is an iPad or iPhone. But it's showing error in the console. What is the reason for this?
<script>
var deviceAgent = navigator.userAgent.toLowerCase();
var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
if (!agentID) {
document.write('<script src="<?php echo get_template_directory_uri(). "/js/modernizr-2.6.2.min.js"?>"></script>'";
}
</script>
My current code is:
<script> var deviceAgent = navigator.userAgent.toLowerCase();
var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
if (!agentID)
document.write('<script src="<?php echo get_template_directory_uri(). "/js/modernizr-2.6.2.min.js"?>"></script>'
</script>
You miss some characters in your 4th line, try to edit this line.
You can also get the url in a specific var before your script in PHP, it'll be easier to avoid errors
$url = get_template_directory_uri() . "/js/modernizr-2.6.2.min.js";
...
<script> var deviceAgent = navigator.userAgent.toLowerCase();
var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
if (!agentID)
document.write('<script src="<?php echo $url ?>"></script>');
</script>
Related
I'm trying to insert a conversion tracking script into a thank you page that one is directed to upon completing a contact form. I'm working in Wordpress and using the WPWOX Custom Script Integration plugin to insert my script, which is as follows:
<!-- Google Code for contact-us/thank-you Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 978060811;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "OmTcCKWT6mQQi4yw0gM";
var google_remarketing_only = false;
/* ]]> */
</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="//www.googleadservices.com/pagead/conversion/978060811/?label=OmTcCKWT6mQQi4yw0gM&guid=ON&script=0"/>
</div>
</noscript>
However, when running Tag Assist I am given the error of "No HTTP response detected".
Any idea why I I'm getting the error? Here is the link to the thank you page http://expoprop.co.za/thank-you/
I want to show product variations which come through the woo-commerce gravity form add-ons
on the cart page in the table after product name column.
Mean I want to show the product options which can change or update after adding to the cart.
How can I do ?
Please help me out to sholve the problem.
Thanks
This would require some heavy customizations to the templates. Not quite that easy considering you'd also have to use AJAX. If you're looking for a place to start, take a look at editing the templates in /wp-content/plugins/woocommerce/cart/ and using template overrides. Not quite an answer here but also not something that can be answered easily.
I my case was a template problem, I fixed this converting my theme in child of twentyxxx theme and adding this code in head section of header.
<script type='text/javascript' src='<?php echo get_stylesheet_directory_uri()?>/js/prettyPhoto/jquery.prettyPhoto.js?ver=3.1.5'></script>
<script type='text/javascript' src='<?php echo get_stylesheet_directory_uri()?>/js/prettyPhoto/jquery.prettyPhoto.init.js?ver=2.2.10'></script>
<script type='text/javascript'>
/* <![CDATA[ */
var wc_single_product_params = {"i18n_required_rating_text":"Please select a rating","review_rating_required":"yes"};
var wc_single_product_params = {"i18n_required_rating_text":"Please select a rating","review_rating_required":"yes"};
/* ]]> */
</script>
<script type='text/javascript' src='<?php echo get_stylesheet_directory_uri()?>/js/frontend/single-product.js?ver=2.2.10'></script>
<script type='text/javascript' src='<?php echo get_stylesheet_directory_uri()?>/js/jquery-blockui/jquery.blockUI.js?ver=2.60'></script>
<script type='text/javascript'>
/* <![CDATA[ */
var woocommerce_params = {"ajax_url":"\/wp-admin\/admin-ajax.php","ajax_loader_url":"\/\/ahrf-preview.nettheory.com\/wp-content\/plugins\/woocommerce\/assets\/images\/ajax-loader#2x.gif"};
var woocommerce_params = {"ajax_url":"\/wp-admin\/admin-ajax.php","ajax_loader_url":"\/\/ahrf-preview.nettheory.com\/wp-content\/plugins\/woocommerce\/assets\/images\/ajax-loader#2x.gif"};
/* ]]> */
</script>
<script type='text/javascript' src='<?php echo get_stylesheet_directory_uri()?>/js/frontend/woocommerce.js?ver=2.2.10'></script>
<script type='text/javascript' src='<?php echo get_stylesheet_directory_uri()?>/js/jquery-cookie/jquery.cookie.js?ver=1.3.1'></script>
<script type='text/javascript'>
/* <![CDATA[ */
var wc_cart_fragments_params = {"ajax_url":"\/wp-admin\/admin-ajax.php","fragment_name":"wc_fragments"};
var wc_cart_fragments_params = {"ajax_url":"\/wp-admin\/admin-ajax.php","fragment_name":"wc_fragments"};
/* ]]> */
</script>
<script type='text/javascript' src='<?php echo get_stylesheet_directory_uri()?>/js/frontend/cart-fragments.js?ver=2.2.10'></script>
<script type='text/javascript' src='http://ahrf-preview.nettheory.com/wp-content/themes/twentyfifteen/js/skip-link-focus-fix.js?ver=20141010'></script>
<script type='text/javascript' src='http://ahrf-preview.nettheory.com/wp-includes/js/comment-reply.js?ver=4.1'></script>
<script type='text/javascript'>
/* <![CDATA[ */
var screenReaderText = {"expand":"<span class=\"screen-reader-text\">expand child menu<\/span>","collapse":"<span class=\"screen-reader-text\">collapse child menu<\/span>"};
/* ]]> */
</script>
<script type='text/javascript' src='http://ahrf-preview.nettheory.com/wp-content/themes/twentyfifteen/js/functions.js?ver=20141212'></script>
<script type='text/javascript'>
/* <![CDATA[ */
var wc_add_to_cart_variation_params = {"i18n_no_matching_variations_text":"Sorry, no products matched your selection. Please choose a different combination.","i18n_unavailable_text":"Sorry, this product is unavailable. Please choose a different combination."};
/* ]]> */
</script>
<script type='text/javascript' src='<?php echo get_stylesheet_directory_uri()?>/js/frontend/add-to-cart-variation.js?ver=2.2.10'></script>
One ad unit just stopped to work and after trying to generate new code it is still not working. When I use google console it is just showing warning Ad unit failed to fetch. Other 3 ads are working normally. They are inserted before I started to work on this project.
New ad code is generated like
header
<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>
<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.defineSlot('/6000854/R300x250_L', [300, 250], 'div-gpt-ad-1367703773182-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
body
<!-- R300x250_L -->
<div id='div-gpt-ad-1367703773182-0' style='width:300px; height:250px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1367703773182-0'); });
</script>
</div>
Old code is generated like
header
<script type='text/javascript' src='http://partner.googleadservices.com/gampad/google_service.js'></script>
<script type='text/javascript'>
GS_googleAddAdSenseService("ca-pub-2838961657718357");
GS_googleEnableAllServices();
</script>
<script type='text/javascript'>
GA_googleAddSlot("ca-pub-2838961657718357", "Top728x90");
GA_googleAddSlot("ca-pub-2838961657718357", "Right300x250");
GA_googleAddSlot("ca-pub-2838961657718357", "Right300x250Bottom");
</script>
<script type='text/javascript'>
GA_googleFetchAds();
</script>
body
<!-- Right300x250Bottom -->
<script type='text/javascript'>
GA_googleFillSlot("Right300x250Bottom");
</script>
Is there maybe conflict because of diferent tags or code
NOTE: I am just wordpress front end developer, I don't have access to google DFP services and I am not generating tags or code
EDIT: Based on this discussion it looks like using the old GAM tags with GPT tags may now be an issue (just recently) http://productforums.google.com/forum/#!topic/dfp/snK7znwUMBE
I think you should convert the GAM tags to to GPT tags and use just the DFP GPT tags if possible to stop this happening... its most probably a conflict between the two scripts and depending on the order they get loaded the GPT tags may not work...
ORIGINAL:
I just tried your code and two ads showed as expected. So there does not appear to be any conflicts using both scripts at the same time.
Potentially you have been refreshing the page so many times that there are no ads that will be displaying for you through DFP anymore because of rate limits? That is just a wild guess though. If I refresh the page a lot I do get the failed to fetch message every now and then in the console so I think it is probably just a rate limit and something that a normal user will not have a problem with.
This is the code that I am using, two 300x250 ads show on the page so everything is working correctly.
<html>
<head>
<title>DFP TEST</title>
<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>
<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.defineSlot('/6000854/R300x250_L', [300, 250], 'div-gpt-ad-1367703773182-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
<script type='text/javascript' src='http://partner.googleadservices.com/gampad/google_service.js'></script>
<script type='text/javascript'>
GS_googleAddAdSenseService("ca-pub-2838961657718357");
GS_googleEnableAllServices();
</script>
<script type='text/javascript'>
GA_googleAddSlot("ca-pub-2838961657718357", "Top728x90");
GA_googleAddSlot("ca-pub-2838961657718357", "Right300x250");
GA_googleAddSlot("ca-pub-2838961657718357", "Right300x250Bottom");
</script>
<script type='text/javascript'>
GA_googleFetchAds();
</script>
</head>
<body>
<!-- R300x250_L -->
<div id='div-gpt-ad-1367703773182-0' style='width:300px; height:250px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1367703773182-0'); });
</script>
</div>
<!-- Right300x250Bottom -->
<script type='text/javascript'>
GA_googleFillSlot("Right300x250Bottom");
</script>
</body>
</html>
is there a way to make Pin It button work with OG
<img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" />
<script type="text/javascript">
(function (w, d, load) {
var script,
first = d.getElementsByTagName('SCRIPT')[0],
n = load.length,
i = 0,
go = function () {
for (i = 0; i < n; i = i + 1) {
script = d.createElement('SCRIPT');
script.type = 'text/javascript';
script.async = true;
script.src = load[i];
first.parentNode.insertBefore(script, first);
}
}
if (w.attachEvent) {
w.attachEvent('onload', go);
} else {
w.addEventListener('load', go, false);
}
}(window, document,
['//assets.pinterest.com/js/pinit.js']
));
</script>
Just wonder if this is something that someone has already figured out or not? Would be nice if this could work that way, will make life simple.
Thanks in advance for any help you can offer!
Here is what I have done to make it work, but not sure if this would be the best way of doing it since it requires to use php echo to echo content of the open graph meta content.
<meta property="og:title" content="Family Budget Spreadsheet for Excel">
<meta property="og:type" content="product">
<meta property="og:url" content="<?php $og_url = $_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']; echo $og_url ?>">
<meta property="og:image" content="<?php $og_image = 'http://www.mysite.com/images/imageIneed.jpg' ; echo $og_image ?>">
<meta property="og:site_name" content="My Sites Name">
<meta property="og:description" content="<?php $og_description = 'My page description'; echo $og_description ?>">
then added following code taken from Pinterest
<img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" />
<script type="text/javascript">
(function (w, d, load) {
var script,
first = d.getElementsByTagName('SCRIPT')[0],
n = load.length,
i = 0,
go = function () {
for (i = 0; i < n; i = i + 1) {
script = d.createElement('SCRIPT');
script.type = 'text/javascript';
script.async = true;
script.src = load[i];
first.parentNode.insertBefore(script, first);
}
}
if (w.attachEvent) {
w.attachEvent('onload', go);
} else {
w.addEventListener('load', go, false);
}
}(window, document,
['//assets.pinterest.com/js/pinit.js']
));
</script>
It is working just fine, but I am sure there is much better way of doing this, so if you have one, please share it here.
Am playing with Google Maps V3 API and StyledMarkers. The data is derived from a PHP/MySQL query returning several hundred points.
The code below returns everything I need and works fine EXCEPT for getting it to zoom to an approriate level (which in this case I know is 10).
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title><?php echo returnval("event_name","events",$_GET['eid']); ?> Map - No Refresh</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="StyledMarker.js"></script>
<script type="text/javascript">
function initialize() {
var myLatLng = new google.maps.LatLng(<?php echo $evlat; ?>, <?php echo $evlng; ?>);
var bounds = new google.maps.LatLngBounds();
var myOptions = {
zoom: 9,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("show_map"), myOptions);
<?php
$iconcntr = 0;
while ($row = mysql_fetch_array($result)) {
$iconcntr ++;
$rfa_no = $row['rfa_no'];
$longitude = $row['longitude'];
$latitude = $row['latitude'];
if ($row['rfa_priority'] == 1) {
$iconclr = "FF0000";
} elseif ($row['rfa_priority'] == 2) {
$iconclr = "FFFF00";
} else {
$iconclr = "FFFFFF";
}
?>
var varLatLng = new google.maps.LatLng(<?php echo $latitude; ?>,<?php echo $longitude; ?>);
bounds.extend(varLatLng);
var styleMaker<?php echo $iconcntr; ?> = new StyledMarker({styleIcon:new StyledIcon(StyledIconTypes.BUBBLE,{color:"<?php echo $iconclr; ?>",text:"<?php echo $rfa_no; ?>"}),position:new google.maps.LatLng('<?php echo $latitude; ?>', '<?php echo $longitude; ?>'),flat:true,zIndex:<?php echo ($iconcntr+1000); ?>,map:map});
<?php
}
?>
map.fitbounds(bounds);
}
</script>
</head />
<body style="margin:0px; padding:0px;" onload="initialize()" />
<div id="show_map" style="width:100%; height:100%;"></div>
</body>
</html>
Anyone have any idea what I'm doing wrong? Not very strong in the programming department.
JavaScript is case-sensitive.
Use map.fitBounds(bounds) instead of map.fitbounds(bounds). Documentation
You should have seen an error in the Javascript Console about fitbounds not being a valid method or something similar.