1

I have written this script in a scripts.js file. And I want execute the first half for only Home page and second half for custom post type page. How can I do this in wordpress ?

 // This Chunk For Home Page  [Part one]
 jQuery("#front-page-slider").responsiveSlides({
              maxwidth: 390,
              "auto": true,
              "pager": false,
               "nav": false,
              "pause": true,
               speed: 800
          });



    // This Chunk is for For Only Custom Post Page [Part Two]
  $("a[rel^='prettyPhoto']").prettyPhoto({animation_speed:'normal',theme:'pp_default',slideshow:3000, autoplay_slideshow: false});
  var width = $(window).width();
1
  • each page type should have specific class on body tag to differentiate Commented Dec 5, 2014 at 16:02

2 Answers 2

1

As suggested in the comments, you can leverage the body class, e.g.:

if(jQuery('body.home').length){alert('home');}
Sign up to request clarification or add additional context in comments.

Comments

0

this is my idea:

in the js:

function PartOneForHome(){
//code bla bla bla
}
function PartTwoForCustomPosts(){
//code bla bla bla
}

in the header.php or footer.php:

<?php if(is_home()) { ?>
  <script> PartOneForHome(); </script>
<?php } else if is any custom post* { ?>
  <script> PartTwoForCustomPosts(); </script>
<?php } ?>

*I dont know how to detect if is a custom post, search for it :D

1 Comment

You really should be using wp_enqueue_script for include JS; read more about it on the WP Codex

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.