WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What is the best practice to apply an individual script to a particular page? When I try to apply the script of the whole page it has problems with other plug-ins. Is there a rule of thumb?

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>


(function() {


var contactForm = {

    container: $('#contact'),

    config: {
        effect: 'slideToggle',
        speed: 500

    init: function(config) {
        $.extend(this.config, config);

        $('<button></button>', {
            text: 'Contact Me'
            .insertAfter( 'article:first' )
            .on( 'click', this.show );

    show: function() {
        var cf = contactForm,
            container = cf.container,
            config = cf.config;

        if ( container.is(':hidden') ) {

    close: function() {
        var $this = $(this), // #contact
            config = contactForm.config;

        if ( $this.find('span.close').length ) return;

        $('<span class=close>X</span>')
            .on('click', function() {
                // this = span

    // effect: 'fadeToggle',
    speed: 300


share|improve this question
Is that for fron-end or back-end? And why do you use an outdated jQuery instead of the built-in version? – toscho Oct 3 '12 at 3:12
front end for a slider. I'm working one tutorial that is a few months old and that is probably why I'm referencing the outdated J query version. Thanks for your response. – simpletwist Oct 3 '12 at 13:56

This url works
and for particular page you can use

if( is_page('x')) { ?>
<?php }
share|improve this answer

I usually register all the scripts I need using wp_register_script and then use wp_enqueue_script inside a conditional for scripts that need to be loaded only on specific pages.


function enqueue_scripts() {
    wp_register_script( 'global', get_template_directory_uri() . '/lib/js/global.js', array( 'jquery' ), '1.0', true );
    wp_register_script( 'example', get_template_directory_uri() . '/lib/js/example.js', array( 'jquery' ), '1.0', true );

    wp_enqueue_script( 'global' );

    if ( is_page( 2 ) ) { // example page
        wp_enqueue_script( 'example' );

add_action( 'wp_enqueue_scripts', 'enqueue_scripts' );
share|improve this answer

Your Answer


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.