• Resolved jerome330

    (@jerome330)


    Hello,

    I’m trying to wrap some javascript in one of my template files using this plugin and a shortcode. Everytime I go to save the page using the below code it causes the page to break and not show any content. Here is the code I’m using below:

    <?php echo do_shortcode(‘[showto browser=”desktop”]
    <div id=”contentclick6964″></div>
    <script type=”text/javascript”>
    (function() {
    var data =
    {
    pub_id: “2818”,w_id: “6964”,pw: “21b55185dff4f8”, cbust: (new Date()).getTime()
    };
    if (typeof widgetCheck6964 === ‘undefined’) {
    var u=””;
    for(var key in data){u+=key+”=”+data[key]+”&”}
    u=u.substring(0,u.length-1);
    var a = document.createElement(“script”);
    a.type= ‘text/javascript’;
    a.src = “https://api.contentclick.co.uk/pub_serve.php?&#8221; + u;
    a.async = true;
    document.getElementById(“contentclick6964”).appendChild(a);
    window.widgetCheck6964 = “set”;
    }
    })();
    </script>
    [/showto]’); ?>

    Could this be conflicting with my javascript ad tag of some sort?

    Thanks in advance for any help you can give me!

    https://www.ads-software.com/plugins/browser-body-classes-with-shortcodes/

Viewing 15 replies - 1 through 15 (of 25 total)
  • Plugin Author thomstark

    (@thomstark)

    That’s because your PHP is full of syntax errors.

    <?php
    
    $content = '<div id="contentclick6964"></div>
    <script type="text/javascript">
    	(function() {
    		var data =
    			{
    				pub_id: "2818",
    				w_id: "6964",
    				pw: "21b55185dff4f8",
    				cbust: (new Date()).getTime()
    			};
    		if (typeof widgetCheck6964 === "undefined")
    		{
    			var u="";
    			for(var key in data){u+=key+"="+data[key]+"&"}
    			u=u.substring(0,u.length-1);
    			var a = document.createElement("script");
    			a.type= "text/javascript";
    			a.src = "https://api.contentclick.co.uk/pub_serve.php?" + u;
    			a.async = true;
    			document.getElementById("contentclick6964").appendChild(a);
    			window.widgetCheck6964 = "set";
    		}
    	})();
    </script>';
    echo do_shortcode('[showto browser="desktop"]'.$content.'[/showto]'); 
    
    ?>
    Thread Starter jerome330

    (@jerome330)

    That’s great! Thanks for fixing this and getting back to me quickly. I’m not very good with PHP as you can tell.

    So is it possible to use this PHP snippet multiple times with different javascript ad tags on the same custom page template?

    Thanks again!

    Plugin Author thomstark

    (@thomstark)

    Use a different variable for each of them. $content for one. $stuff for two. $junk for three. Whatever you want.

    Plugin Author thomstark

    (@thomstark)

    Note that the $content variable is wrapped in single quotes. So all the quotes in your js need to be double quotes, or escaped single quotes, like this: \’stuff\’

    Thread Starter jerome330

    (@jerome330)

    Does this look right?

    <?php

    $adtag = ‘<div id=”contentclick11882″></div>
    <script type=”text/javascript”>
    (function() {
    var data =
    {
    pub_id: “2818”,w_id: “11882”,pw: “e8b49fec695569”, cbust: (new Date()).getTime()
    };
    if (typeof widgetCheck11882 === ‘undefined’) {
    var u=””;
    for(var key in data){u+=key+”=”+data[key]+”&”}
    u=u.substring(0,u.length-1);
    var a = document.createElement(“script”);
    a.type= ‘text/javascript’;
    a.src = “https://api.contentclick.co.uk/pub_serve.php?&#8221; + u;
    a.async = true;
    document.getElementById(“contentclick11882”).appendChild(a);
    window.widgetCheck11882 = “set”;
    }
    })();
    </script>’;
    echo do_shortcode(‘[showto browser=”tablet”]’.$adtag.'[/showto]’);

    ?>

    Thread Starter jerome330

    (@jerome330)

    Never mind, I think I figured it out. I was missing the double quotes on a.type and undefined.

    Plugin Author thomstark

    (@thomstark)

    That’s right. Otherwise looks good.

    Thread Starter jerome330

    (@jerome330)

    Great! Thanks for all your help with this! Awesome plugin BTW. This has saved me a lot of time and frustration. I’m going to have to check out some of your films as well as I use to be a editor and sound guy.

    Thanks again!

    Plugin Author thomstark

    (@thomstark)

    Not a problem. Have fun and enjoy.

    Plugin Author thomstark

    (@thomstark)

    Another way you could do all this of course is pure jquery, based off of the body classes that my plugin creates.

    if $('body').hasClass('desktop')
    {
     // function here
    }
    else if $('body').hasClass('tablet')
    {
      // function here
    }
    else if $('body').hasClass('mobile')
    {
      // function here
    }
    Thread Starter jerome330

    (@jerome330)

    Hi, so I’m currently using your plugin on a few of my sites and I am noticing that sometimes they are firing the wrong ad size on Desktop. It seems to be firing mobile ads and tablet ads on Desktop.

    I am using the following code below in my custom page templates.

    <?php echo do_shortcode(‘[showto browser=”desktop”]<!– BEGIN JS TAG – FC – Desktop – 728×90 – bottom near footer < – DO NOT MODIFY –>
    <SCRIPT SRC=”https://ib.adnxs.com/ttj?id=4566612&#8243; TYPE=”text/javascript”></SCRIPT>
    <!– END TAG –>[/showto]’); ?>

    This seems to be working for the most part minus the misfires? Could it be something else?

    Thanks in advance for any help you can give me!

    Plugin Author thomstark

    (@thomstark)

    I only see the desktop ad in here. What about the mobile and tablet ads? Where’s the rest of the code?

    Thread Starter jerome330

    (@jerome330)

    Below is all of the code from one of my custom page templates:

    [excessive and mangled code removed – please use a pastebin see:
    https://codex.www.ads-software.com/Forum_Welcome#Posting_Code ]

    Plugin Author thomstark

    (@thomstark)

    Your code was removed by WordPress.

    Thread Starter jerome330

    (@jerome330)

    Here is the code again.

    <?php
    /**
     * Template Name: Ads
     */
    ?>
    
    <?php $mts_options = get_option(MTS_THEME_NAME); ?>
    <?php get_header(promo); ?>
    
    <!-- InterYield Ad Tag -->
    <script src="https://interyield.td553.com/InterYield/bindevent.do?e=click&affiliate=lyfe2015&subid=foreverceleb&ecpm=0&debug=false&snoozeMinutes=3&adCountIntervalHours=24&maxAdCountsPerInterval=1&pop=under&attributionDisabled=true&endpoint=http%3A%2F%2Finteryield.td553.com" type="text/javascript"></script>
    <!--EO InterYield Ad Tag -->
    
    <div id="page" class="single">
    	<article class="article">
    		<div id="content_box" >
    			<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    				<div id="post-<?php the_ID(); ?>" <?php post_class('g post'); ?>>
    					<div class="single_page">
    						<?php if ($mts_options['mts_breadcrumb'] == '1') { ?>
    							<div class="breadcrumb" xmlns:v="https://rdf.data-vocabulary.org/#"><?php mts_the_breadcrumb(); ?></div>
    						<?php } ?>
    						<header>
    							<h1 class="title entry-title"><?php the_title(); ?></h1>
    						</header>
    
    <!-- LYFEMEDIA ADS -->
    
    <div id="lm-center-ads">
    <?php echo do_shortcode('[showto browser="desktop"]<!-- BEGIN JS TAG - FC - Desktop - 728x90 - just below article title < - DO NOT MODIFY -->
    <SCRIPT SRC="https://ib.adnxs.com/ttj?id=4566610" TYPE="text/javascript"></SCRIPT>
    <!-- END TAG -->[/showto]'); ?>
    
    <?php echo do_shortcode('[showto browser="tablet"]<!-- BEGIN JS TAG - FC - Tablet - 300x250 - just below article title < - DO NOT MODIFY -->
    <SCRIPT SRC="https://ib.adnxs.com/ttj?id=4566622" TYPE="text/javascript"></SCRIPT>
    <!-- END TAG -->[/showto]'); ?>
    
    <?php echo do_shortcode('[showto browser="mobile"]<!-- BEGIN JS TAG - FC - Mobile - 300x250 - below content.ad widget < - DO NOT MODIFY -->
    <SCRIPT SRC="https://ib.adnxs.com/ttj?id=4566628" TYPE="text/javascript"></SCRIPT>
    <!-- END TAG -->[/showto]'); ?>
    </div>
    
    <!--EO LYFEMEDIA ADS -->
    
    						<div class="post-content box mark-links entry-content">
    							<?php the_content(); ?>
    <?php wp_pagenavi( array( 'type' => 'multipart' ) ); ?>
    							<? // php wp_link_pages(array('before' => '<div class="pagination">', 'after' => '</div>', 'link_before'  => '<span class="current"><span class="currenttext">', 'link_after' => '</span></span>', 'next_or_number' => 'next_and_number', 'nextpagelink' => __('Next','mythemeshop'), 'previouspagelink' => __('Previous','mythemeshop'), 'pagelink' => '%','echo' => 1 )); ?>
    						</div><!--.post-content box mark-links-->
    					</div>
    				</div>
    
    <!-- LYFEMEDIA ADS -->
    
    <div id="lm-center-ads">
    <?php echo do_shortcode('[showto browser="desktop"]<!-- BEGIN JS TAG - FC - Desktop - 728x90 - below content nav bar < - DO NOT MODIFY -->
    <SCRIPT SRC="https://ib.adnxs.com/ttj?id=4566611" TYPE="text/javascript"></SCRIPT>
    <!-- END TAG -->[/showto]'); ?>
    
    <?php echo do_shortcode('[showto browser="tablet"]<!-- BEGIN JS TAG - FC - Tablet - 728x90 - below content nav bar < - DO NOT MODIFY -->
    <SCRIPT SRC="https://ib.adnxs.com/ttj?id=4566621" TYPE="text/javascript"></SCRIPT>
    <!-- END TAG -->[/showto]'); ?>
    
    <?php echo do_shortcode('[showto browser="mobile"]<!-- BEGIN JS TAG - FC - Mobile - 320x100 - below content nav bar < - DO NOT MODIFY -->
    <SCRIPT SRC="https://ib.adnxs.com/ttj?id=4566627" TYPE="text/javascript"></SCRIPT>
    <!-- END TAG -->[/showto]'); ?>
    </div>
    
    <!--EO LYFEMEDIA ADS -->
    				<? // php comments_template( '', true ); ?>
    			<?php endwhile; ?>
    		</div>
    
    <!-- ContentClick Ads -->
    
    <div id="contentclick6430"></div>
    <script type="text/javascript">
        (function() {
            var data =
            {
                pub_id: "2818",w_id: "6430",pw: "a2158c6813126f", cbust: (new Date()).getTime()
            };
    	if (typeof widgetCheck6430 === 'undefined')   {
            var u="";
            for(var key in data){u+=key+"="+data[key]+"&"}
            u=u.substring(0,u.length-1);
            var a = document.createElement("script");
            a.type= 'text/javascript';
            a.src = "https://api.contentclick.co.uk/pub_serve.php?" + u;
            a.async = true;
            document.getElementById("contentclick6430").appendChild(a);
    	window.widgetCheck6430 = "set";
    	}
        })();
    </script>
    
    <!-- EO ContentClick Ads -->
    
    <!-- ContentAd Ads -->
    
    <div id="contentad29125"></div>
    <script type="text/javascript">
        (function() {
            var params =
            {
                id: "209f85a0-71a9-4d2b-accb-3e1d61e0c150",
                d:  "Zm9yZXZlcmNlbGViLmNvbQ==",
                wid: "29125",
                cb: (new Date()).getTime()
            };
    
            var qs="";
            for(var key in params){qs+=key+"="+params[key]+"&"}
            qs=qs.substring(0,qs.length-1);
            var s = document.createElement("script");
            s.type= 'text/javascript';
            s.src = "https://api.content.ad/Scripts/widget.aspx?" + qs;
            s.async = true;
            document.getElementById("contentad29125").appendChild(s);
        })();
    </script>
    
    <!-- EO ContentAd Ads -->
    
    <!-- LYFEMEDIA ADS -->
    
    <div class="left-promo-ad">
    <?php echo do_shortcode('[showto browser="desktop"]<!-- BEGIN JS TAG - FC - Desktop - 300x250 - bottom left below content.ad < - DO NOT MODIFY -->
    <SCRIPT SRC="https://ib.adnxs.com/ttj?id=4566614" TYPE="text/javascript"></SCRIPT>
    <!-- END TAG -->[/showto]'); ?>
    </div>
    
    <?php echo do_shortcode('[showto browser="desktop"]<!-- BEGIN JS TAG - FC - Desktop - 300x250 - bottom right below content.ad < - DO NOT MODIFY -->
    <SCRIPT SRC="https://ib.adnxs.com/ttj?id=4566615" TYPE="text/javascript"></SCRIPT>
    <!-- END TAG -->[/showto]'); ?>
    
    <!--EO LYFEMEDIA ADS -->
    
    <?php echo do_shortcode('[showto browser="tablet"]<div id="taboola-sidebar"></div>
    <script type="text/javascript">
      window._taboola = window._taboola || [];
      _taboola.push({
        mode: "thumbnails-a",
        container: "taboola-sidebar",
        placement: "Sidebar",
        target_type: "mix"
      });
    </script>[/showto]'); ?>
    
    <div class="fc-related">
    <?php if ( function_exists( 'echo_ald_crp' ) ) echo_ald_crp(); ?>
    </div>
    	</article>
    
    	<?php get_sidebar(); ?>
    <?php get_footer(promo); ?>
Viewing 15 replies - 1 through 15 (of 25 total)
  • The topic ‘Javascript within php echo do_shortcode’ is closed to new replies.