title: Wordpress - Custom page includes second custom page causing problems with functions file
body: <p>Alright so I have a custom page template designed with javascript and php (lets call this page1). The javascript inserts a second custom page (page2) template which displays content inside a div called contained on page1.</p>
  
  <p>The problem I have is <blockquote>Fatal error: Cannot redeclare contentAd() (previously declared in /home/content/70/8886870/html/wp-content/themes/myTheme/functions.php:20) in /home/content/70/8886870/html/wp-content/themes/myTheme/functions.php on line 23</blockquote></p>
  
  <p>The function in question runs as part of a hook. This is not a question of a child theme's functions.php being the same as the parent. This is far more complex..</p>
  
  <p>I know precisely why this is occurring: Since page1 is the container for page2, the functions in functions.php run when the page is loaded (as it should). However, because page2 includes wp-blog-header.php (necessary for custom wp queries and metadata calls), when the javascript runs through page2 to insert its content inside page1, the very same functions.php runs again and causes the above error.</p>
  
  <p>I'm looking for a way around this. The javascript runs automatically on page load through ajax. Page2 must exist outside of page1 - they cannot be merged in any way. Page1 and Page2 do NOT use the same hooks. Page2 in fact, doesn't even call to function contentAd(). This is entirely an issue of functions.php executing more than once because of the ajax call.</p>
  
  <p>Is there a way to prevent functions.php from executing on a given page? Otherwise, I'm open to your suggestions!</p>
  
  <p>Page1:</p>
  
  <pre><code>&lt;?php
  /*
  Template Name: Page1
  */
  ?&gt;
  
  &lt;?php get_header(); ?&gt;
  
  &lt;script type="text/javascript" src="../wp-content/themes/myTheme/insert.js"&gt;&lt;/script&gt;
  &lt;div id="content"&gt;
      &lt;div class="padder"&gt;
          &lt;?php do_action( 'bp_before_blog_home' ) ?&gt;
          &lt;?php do_action( 'template_notices' ) ?&gt;
          &lt;div class="page" id="blog-latest" role="main"&gt;
          &lt;div class="spacer" style="float:left;"&gt;&amp;nbsp&lt;/div&gt;
  
          &lt;div class="spacer" style="float:right;"&gt;&amp;nbsp&lt;/div&gt;
              &lt;ol class="row" id="updates"&gt;
                  &lt;div id="contained"&gt;&lt;/div&gt;
              &lt;/ol&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;?php get_sidebar() ?&gt;
  &lt;?php get_footer() ?&gt;
  </code></pre>
  
  <p>insert.js:</p>
  
  <pre><code>$(document).ready(function() {
      $('#contained').load('../wp-content/themes/myThemes/page2.php');
  });
  </code></pre>
  
  <p>Page2:</p>
  
  <pre><code>&lt;?php include("../../../wp-blog-header.php"); ?&gt;
  A whole bunch of code sits in here but keeping the above line all by itself still produces the error hence my theory.
  </code></pre>