Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to write a simple plugin. For every time a page is viewed, it will write to the MySQL database. Then, if the current hour is odd, it will set a PHP variable of $is_odd to true;

<?php
  require_once('library-of-functions-to-support-this-plugin.php');
  function_to_write_to_mysql_db();
  $is_odd = false;
  if(current_hour_odd()) {
    $is_odd=true;
  }
  $is_odd_json = json_encode($is_odd);
?>

Then, it should embed the following JavaScript (note: I've already modified the theme's templates to put an on each page):

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
   var odd = <?php echo $is_odd_json; ?>;
   if(odd) {
      $("#OddElement").html('Odd!');
   }
</script>

So basically, I have no idea where to put these code snippets. What filters do I want to apply? I know this plugin seems stupid, but it's laying the groundwork for something else I want to do.

Thanks so much!

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You could attach the to wp_head action http://codex.wordpress.org/Plugin_API/Action_Reference/wp_head

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.