How to call a javascript script in single.php header

Discussion in 'PHP' started by charlyms21, Jan 28, 2010.

  1. #1
    I asked this question on wordpress forum,seems like noone have any idea of this
    I am having to display both ad sense and cpalead javascript in all posts,so while making itself calling cpalead javascript for the header,what should I do with this?

    single.php starts with



    <?php get_header(); ?>
    <?php
    global $options;
    foreach ($options as $value) {
    if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); } }
    ?>
    <div id="container">

    <div id="left-div">

    <?php if (have_posts()) : ?>

    <?php while (have_posts()) : the_post(); ?>
     
    charlyms21, Jan 28, 2010 IP
  2. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #2
    <?php if (is_single()) { ?>

    Add code here

    <?php } ?>

    try that in ur header.php
     
    Bohra, Jan 28, 2010 IP
  3. charlyms21

    charlyms21 Peon

    Messages:
    178
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    No I dont want it to include the script in my main header.But only call it in single.php file as its header and retain the home and other pages without that script.I hope you understood what I meant,thnks in advance
     
    charlyms21, Jan 29, 2010 IP
  4. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #4
    when u put that code in your header.php then it will only show when the single.php is called
     
    Bohra, Jan 29, 2010 IP
  5. charlyms21

    charlyms21 Peon

    Messages:
    178
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    No if I put that Javascript in my header,it will harm my search engine ranking,thats why I cant do that,what I need is to call the header function as a seperate .js file
     
    charlyms21, Jan 30, 2010 IP
  6. HivelocityDD

    HivelocityDD Peon

    Messages:
    179
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I am not sure about your question. Still I think this

    1) in single.php why cant you include the js script like this


    
    
    <?php
    echo "<script type='javascript'>";
    include "your js file name with path";
    echo "</script>";
    
    ?>
    
    
    PHP:
    If you are trying to call the function inside the js file you can do it like this.

    
    
    <?php
     
    echo "<script type='javascript'>functionName();</script>";
    
    ?>
    
    PHP:
    Hope this helps.
     
    Last edited: Jan 30, 2010
    HivelocityDD, Jan 30, 2010 IP