• Resolved bella2011

    (@bella2011)


    Hi there,

    This is a great plugin! Works really well for inserting Google Adsense tags into a theme.

    However, run across an issue with Google Ad Manager tags (formerly DFP).

    When I use this tag, I receive an error message:

    <!-- /22394762/Article_728x90_ATF -->
    <div id='div-gpt-ad-3843543546464364-0' style='height:90px; width:728px;'>
    <script>
    googletag.cmd.push(function() { googletag.display('div-gpt-ad-3843543546464364-0'); });
    </script>
    </div>

    This is the full snippet:

    function google_ads() {
    return '<!-- /22394762/Article_728x90_ATF -->
    <div id='div-gpt-ad-3843543546464364-0' style='height:90px; width:728px;'>
    <script>
    googletag.cmd.push(function() { googletag.display('div-gpt-ad-3843543546464364-0'); });
    </script>
    </div>';
    }
    add_shortcode('adsense-ros-atf', 'google_ads');

    I receive PARSE ERRORS.

    https://www.dropbox.com/s/kqww1ju17rughzb/Screenshot%202019-03-02%2018.21.55.png?dl=0

    https://www.dropbox.com/s/co0a7gzyxjh872p/Screenshot%202019-03-02%2018.21.59.png?dl=0

    Is there a fix for this by chance?

    • This topic was modified 5 years, 9 months ago by bella2011.
    • This topic was modified 5 years, 9 months ago by bella2011.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hey,

    Your HTML/JavaScript codes includes single quotation marks ', while also being enclosed in single quotation marks to make it into a PHP string.

    In order to fix this, you can either use double quotation marks " to enclose the PHP string, or escape the single quotation marks inside the HTML/JS code using a backslash \':

    add_shortcode( 'adsense-ros-atf', function () {
    	return "<!-- /22394762/Article_728x90_ATF -->
    		<div id='div-gpt-ad-3843543546464364-0' style='height:90px; width:728px;'>
    			<script>googletag.cmd.push(function() { googletag.display('div-gpt-ad-3843543546464364-0'); });</script>
    		</div>";
    } );

    Alternatively, you can use output buffering to remove the need to worry about PHP strings:

    add_shortcode( 'adsense-ros-atf', function () {
    	ob_start(); ?>
    
    <!-- /22394762/Article_728x90_ATF -->
    <div id='div-gpt-ad-3843543546464364-0' style='height:90px; width:728px;'>
    	<script>googletag.cmd.push(function() { googletag.display('div-gpt-ad-3843543546464364-0'); });</script>
    </div>
    
    	<?php
    	return ob_end_clean();
    } );
    Thread Starter bella2011

    (@bella2011)

    Really helpful. Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Problem adding Google Ad Manager (DFP) Tags’ is closed to new replies.