I am trying to replace a google ad unit with a media.net ad

I am trying to replace a google ad unit with a media.net ad unit in functions.php, which should be straight forward, but it keeps giving me this error:

[Fri May 06 14:34:58.351191 2016] [:error] [pid 7313] [client 46.101.46.249:20510] PHP Parse error: syntax error, unexpected 'https' (T_STRING) in /nas/content/live/wellbuzz/wp-content/themes/metro-pro/functions.php on line 236, referer: http://www.wellbuzz.…orrhoids-advice-home-remedies/

I am just replacing:

if (!wp_is_mobile())
{
$ad_before = '<div id="postWedgeLeft">
<script async src="//pagead2.googlesyndic…n.com/pagead/js/adsbygoogle.js"></script>
<!-- WellBuzz Above Nav Buttons Desktop -->
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-7412812612421318"
data-ad-slot="1259349632"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>';
}

with the following:

if (!wp_is_mobile())
{
$ad_before = '<div id="postWedgeLeft">
<script id="mNCC" language="javascript">
medianet_width = "728";
medianet_height = "90";
medianet_crid = "531785681";
medianet_versionId = "111299";
(function() {
var isSSL = 'https:' == document.location.protocol;
var mnSrc = (isSSL ? 'https:' : 'http:') + '//contextual.media.net/nmedianet.js?cid=8CUH42P70' + (isSSL ? '&https=1' : '');
document.write('<scr' + 'ipt type="text/javascript" id="mNSC" src="' + mnSrc + '"></scr' + 'ipt>');
})();
</script>
</div>';
}

What is causing this syntax error to occur? I have put the old ad code back, because otherwise the page does not load, but I still need to resolve this issue of how to put in the new ad code instead.

Thanks for your help...

  • Ivan Shulev

    Hey d-invent ,

    I hope you are having a nice day so far!

    The issue with your code seems to be with the single quotes around the strings https and http. You should either replace them with double quotes or escape them with "/" symbols.

    More on this here - http://www.scriptingok.com/tutorial/Single-quotes-vs-double-quotes-in-PHP

    I would try the following code:

    <?php
    	if(!wp_is_mobile())
    	{
    		$ad_before = '<div id="postWedgeLeft">
    			<script id="mNCC" language="javascript">
    				medianet_width = "728";
    				medianet_height = "90";
    				medianet_crid = "531785681";
    				medianet_versionId = "111299";
    				(function() {
    					var isSSL = "https:" == document.location.protocol;
    					var mnSrc = (isSSL ? "https:" : "http:") + "//contextual.media.net/nmedianet.js?cid=8CUH42P70" + (isSSL ? "&https=1" : "");
    					document.write(\'<scr\' + \'ipt type="text/javascript" id="mNSC" src="\' + mnSrc + \'"></scr\' + \'ipt>\');
    				})();
    			</script>
    		</div>';
    	}

    I hope this helps and I wish you an awesome day ahead!

    Ivan

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.