Title: Javascript within php echo do_shortcode
Last modified: August 22, 2016

---

# Javascript within php echo do_shortcode

 *  Resolved [jerome330](https://wordpress.org/support/users/jerome330/)
 * (@jerome330)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/javascript-within-php-echo-do_shortcode-1/)
 * 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](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://wordpress.org/plugins/browser-body-classes-with-shortcodes/](https://wordpress.org/plugins/browser-body-classes-with-shortcodes/)

Viewing 15 replies - 1 through 15 (of 25 total)

1 [2](https://wordpress.org/support/topic/javascript-within-php-echo-do_shortcode-1/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/javascript-within-php-echo-do_shortcode-1/page/2/?output_format=md)

 *  Plugin Author [thomstark](https://wordpress.org/support/users/thomstark/)
 * (@thomstark)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/javascript-within-php-echo-do_shortcode-1/#post-5829252)
 * 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](https://wordpress.org/support/users/jerome330/)
 * (@jerome330)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/javascript-within-php-echo-do_shortcode-1/#post-5829266)
 * 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](https://wordpress.org/support/users/thomstark/)
 * (@thomstark)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/javascript-within-php-echo-do_shortcode-1/#post-5829268)
 * Use a different variable for each of them. $content for one. $stuff for two. 
   $junk for three. Whatever you want.
 *  Plugin Author [thomstark](https://wordpress.org/support/users/thomstark/)
 * (@thomstark)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/javascript-within-php-echo-do_shortcode-1/#post-5829269)
 * 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](https://wordpress.org/support/users/jerome330/)
 * (@jerome330)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/javascript-within-php-echo-do_shortcode-1/#post-5829272)
 * 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](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](https://wordpress.org/support/users/jerome330/)
 * (@jerome330)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/javascript-within-php-echo-do_shortcode-1/#post-5829274)
 * Never mind, I think I figured it out. I was missing the double quotes on a.type
   and undefined.
 *  Plugin Author [thomstark](https://wordpress.org/support/users/thomstark/)
 * (@thomstark)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/javascript-within-php-echo-do_shortcode-1/#post-5829277)
 * That’s right. Otherwise looks good.
 *  Thread Starter [jerome330](https://wordpress.org/support/users/jerome330/)
 * (@jerome330)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/javascript-within-php-echo-do_shortcode-1/#post-5829281)
 * 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](https://wordpress.org/support/users/thomstark/)
 * (@thomstark)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/javascript-within-php-echo-do_shortcode-1/#post-5829284)
 * Not a problem. Have fun and enjoy.
 *  Plugin Author [thomstark](https://wordpress.org/support/users/thomstark/)
 * (@thomstark)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/javascript-within-php-echo-do_shortcode-1/#post-5829286)
 * 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](https://wordpress.org/support/users/jerome330/)
 * (@jerome330)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/javascript-within-php-echo-do_shortcode-1/#post-5829503)
 * 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=”[http://ib.adnxs.com/ttj?id=4566612&#8243](http://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](https://wordpress.org/support/users/thomstark/)
 * (@thomstark)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/javascript-within-php-echo-do_shortcode-1/#post-5829504)
 * 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](https://wordpress.org/support/users/jerome330/)
 * (@jerome330)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/javascript-within-php-echo-do_shortcode-1/#post-5829505)
 * Below is all of the code from one of my custom page templates:
    _ [excessive 
   and mangled code removed – please use a pastebin see: [http://codex.wordpress.org/Forum\_Welcome#Posting\_Code](http://codex.wordpress.org/Forum_Welcome#Posting_Code)]
 *  Plugin Author [thomstark](https://wordpress.org/support/users/thomstark/)
 * (@thomstark)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/javascript-within-php-echo-do_shortcode-1/#post-5829506)
 * Your code was removed by WordPress.
 *  Thread Starter [jerome330](https://wordpress.org/support/users/jerome330/)
 * (@jerome330)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/javascript-within-php-echo-do_shortcode-1/#post-5829507)
 * 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="http://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="http://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="http://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="http://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="http://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="http://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="http://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="http://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 = "http://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="http://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="http://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)

1 [2](https://wordpress.org/support/topic/javascript-within-php-echo-do_shortcode-1/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/javascript-within-php-echo-do_shortcode-1/page/2/?output_format=md)

The topic ‘Javascript within php echo do_shortcode’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/browser-body-classes-with-shortcodes_ebecee.
   svg)
 * [Browser Body Classes with Shortcodes](https://wordpress.org/plugins/browser-body-classes-with-shortcodes/)
 * [Support Threads](https://wordpress.org/support/plugin/browser-body-classes-with-shortcodes/)
 * [Active Topics](https://wordpress.org/support/plugin/browser-body-classes-with-shortcodes/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/browser-body-classes-with-shortcodes/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/browser-body-classes-with-shortcodes/reviews/)

 * 25 replies
 * 2 participants
 * Last reply from: [jerome330](https://wordpress.org/support/users/jerome330/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/javascript-within-php-echo-do_shortcode-1/page/2/#post-5829520)
 * Status: resolved