How to add Header Javascript in individual pages?

Discussion in 'WordPress' started by charlyms21, Jan 15, 2010.

  1. #1
    Hey, I'm trying to add a little javascript to my posts but NOT my main page. If I stick it in the header it works fine but it shows up on my index as well, so I just want it in the singlepost.php but it doesn't work there, any help would be VERY appreciated.
    I am using wordpress and the javascript which I am trying to execute is a header script.I dont want it to run on my main page,but only on individual page,can you suggest me how to do that
     
    charlyms21, Jan 15, 2010 IP
  2. sevnrock

    sevnrock Peon

    Messages:
    241
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Use this code in your header.php:

    <?php if(is_post()) : ?>
    enter javascript code here
    <?php endif; ?>

    If it's a post, it will show the javascript code. If you want it on your pages as well use

    <?php if(is_post() || is_page()) : ?> instead
     
    sevnrock, Jan 15, 2010 IP
  3. Wp-Mod.Com

    Wp-Mod.Com Peon

    Messages:
    381
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i'd also recommend what sevnrock has to say , great idea
     
    Wp-Mod.Com, Jan 15, 2010 IP
  4. johagulo

    johagulo Peon

    Messages:
    879
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Is it only possible to need to select your themes from a preselected number of themes. You cannot hack and edit these themes as per your liking.
     
    johagulo, Jan 16, 2010 IP
  5. charlyms21

    charlyms21 Peon

    Messages:
    178
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for the reply,but what if I want that script to be displayed on certain posts and certain pages and how to exclude the home page from it?
     
    charlyms21, Jan 17, 2010 IP
  6. Wp-Mod.Com

    Wp-Mod.Com Peon

    Messages:
    381
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #6
    <?php if(is_single(array(17, 19, 1, 11))) : ?>
    enter javascript code here
    <?php endif; ?>

    the no. in red are id of page add them and it will show on certain posts only
     
    Wp-Mod.Com, Jan 17, 2010 IP
  7. charlyms21

    charlyms21 Peon

    Messages:
    178
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    But I dont want to execute that Javascript in my header script as it will penalize my website in SEO results.What I want is to lock specific videos using that Javascript so that Search engines wont penalize my home page because of that Javascript
     
    charlyms21, Jan 18, 2010 IP