Nov
24
Posted on 24-11-2007
Categories: ajax, javascript, trucco, wordpress - Author: Mat on 24-11-2007

Did you insert Javascript code into a post or a page, but it doesn’t run?
Yes, because also without advanced editor the code into script will be changed, it will containes <p> tags and your script won’t be interpreted. So the solution is simply: first you should think if your code is useful in many pages. If it is so, you can include this line in your header.php file:

—HEADER.PHP—

<script type="text/javascript" src="/scripts/updatepage.js"></script>

And to call function contaied in the script, and to execute other js code, you can write code into post/page in this way:

—POST/PAGE CODE—

<script type="text/javascript">
<!–
updatepage();
…other js code…
//–></script>

Otherwise if the code is useful only in that post/page, you can include the first line directly into the post/page code:

—POST/PAGE CODE—

<script type="text/javascript" src="/scripts/updatepage.js"></script>
<script type="text/javascript">
<!–
updatepage();
…other js code…
//–></script>

In the last case, if you want to put code in all posts/pages you can edit file single.php (posts) or page.php (pages):

—HEADER.PHP—

—SINGLE.PHP OR PAGE.PHP—

<h3 class="storytitle">
<a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?></a>
</h3>
<div class="emailpage">
<script type="text/javascript">
<!–
emailpage();
//–>
</script>
</div>


 
Post a Comment
Name:
Email:
Website:
Comments: