title: File write triggering multiple times in Wordpress shortcode?
body: <p>I have written a simple hit counter shortcode in Wordpress using a text file and I have found out that it is somehow triggering the file write process multiple times.</p>
  
  <pre><code>function sc_page_counter() {
      $fname = get_stylesheet_directory() . "/counter.txt";
  
      if (!file_exists($fname)) {
          file_put_contents($fname, "0");
      }
  
      $ct = file_get_contents($fname);
      file_put_contents($fname, ++$ct);
  
      return $ct;
  }
  add_shortcode('page_counter', 'sc_page_counter');
  </code></pre>
  
  <p>I have put the shortcode call in my footer.php</p>
  
  <pre><code>This site has been visited &lt;?php echo do_shortcode('[page_counter]') ?&gt; times.
  </code></pre>
  
  <p>Let's say the current content of counter.txt is 20. The shortcode will correctly output "21" but upon checking the counter.txt file. It is now "25". Results vary whether I'm running it locally or in the production server.</p>
  
  <p>I tried testing it further by just appending a character instead of writing the new value and it appended it about 32 times. I'm currently stumped on why this is happening.</p>