Archived

This topic is now archived and is closed to further replies.

  • 0

Conditional Scripts call in headerscript depending on page


Question

Posted · Report post

I've searched all the forums but can't find the simple answer to what I think is a simple question (but then I am new to this so I think everything is simple until it shows me it is not!)

 

:D

 

I think I have a JQuery conflict with plugins, as a Password Strength meter has suddenly stopped working after I added some functionality on anew page.

 

so I think need to call a couple of Scripts only on a single page - in this case page 119. - to stop the Conflict.

 

Normally if I was hand-coding I would put this in the headerscipt section of the individual page, but with Pagelines We are encouraged to use the headerscripts section under Site Options > custom Code.

 

I have typed this simple bit of php in the header-section but it still seems to call it on every page.....

Any ideas what I am doing wrong.

<?php if(is_page('119')){ ?>

<!-- the path for the library -->
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

<?php } ?>

URL is http://www.focusforhumanity.org

Share this post


Link to post
Share on other sites

3 answers to this question

Posted · Report post

Firstly you cant put ANY php in the javascript headers area. it javascript only there.

 

Secondly your including 2 libs that are bundled by wordpress anyway. and jQuery is already loaded on every page.

 

So you just need to include the ui libs on that page.

 

In your child theme functions.php add:

add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
function my_scripts_method() {
    if( is_page( 119 ) ) {
        wp_enqueue_script( 'jquery-ui' );
    }
}

Share this post


Link to post
Share on other sites

Posted · Report post

THe page with the script loaded in the header script looks fine - 

post-44547-0-64119200-1370096881_thumb.p

 

I then removed the script form the header and loaded it into Plugins/pagelines-customise>functions.php

THis then caused the page layout to mess-up .....clearly it is not calling the UJQuery UI...so I've put it back as it was

 

post-44547-0-22782200-1370096895_thumb.p

 

Sadly this means I still haven't resolved the conflict

 

IS the PHP code in the right place? Should the 

if( is_page( 119 ) )

  have single quotes around the 119 page number?

Share this post


Link to post
Share on other sites