Tag Info

New answers tagged

1

It looks like you've overlooked the 5th input parameter of: wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); Namely the boolean $in_footer part, that will put the script in the footer, if set as true, else in the header. You can also use $deps to handle dependencies. Check out the Codex for more info. => I would stick to ...


0

To all of you struggling to get custom scripts running from functions.php, here's how: WP v4.1.2 Th post is a custom template post I needed to load 3 JSs - parsleyjs.js, he.js (i18n), custom_JsScript.js I also wanted to have the CSS on a separate file Only load these for a specific post function donate_adding_scripts() { if (is_singular()) { global ...


0

What if you completely remove the loadDonateScripts function and just add the conditional before enqueuing the scripts like in the the following: function donate_adding_scripts() { if (is_single()) { global $post; if($post->ID=="8436"){ // only for post Id = 8436 wp_register_script('donateParsleyJs', get_template_directory_uri() . ...


0

You can use get_stylesheet_directory_uri(); while enqueuing the scripts and styles. It returns the directory path in which your child stylesheet is stored.


1

You page is generating two errors: Uncaught TypeError: undefined is not a function. This is likely due to the fact that WordPress sets jQuery to NoConflict mode. Your script is using the $ shortcut and is failing. Modify your script accordingly, either replacing the shortcut or wrapping the jQuery. ...


0

Ahh, solved it with this! add_action( 'wp_head', 'jQuery_UI_Tabs' ); function jQuery_UI_Tabs() { if ( is_page_template('course-landing-page.php' ) ) { echo'<script> $(function() { $( "#tabs" ).tabs(); }); </script>'; }


0

This is a common question. It plagued me when I first started because it doesn't make any sense and it is hard to search for until you know. The problem is that WordPress bundles a version of jQuery that is set to noConflict mode. Therefore, to run scripts you must use noConflict wrappers jQuery(document).ready(function($) { // Inside of this function, ...


1

Try to add the code to the footer using add_action('wp_footer', 'front_js', 99); where 99 specifies the order in which the functions are executed. Now it should be executed after your scripts are loaded.


0

Instead of putting the code in function and hooking it to wp_footer. You can have another JS file stored in your plugin folder and enqueued it like other scripts you enqueued. OR <?php function front_js() { if ( wp_script_is( 'jquery', 'done' ) ) { ?> <script type="text/javascript"> $(document).ready(function(){ ...


4

Actually all styles should be placed in header. So WordPress doesn't have a parameter for doing this in the wp_enqueue_style function. ADDED: OK, if you really want to do it, there is a way. You can use print_late_styles() function which is called in footer. You just need to enqueue your styles when header is already passed. So you need to find some hook ...


0

thanks alot @Antonie Guillien, it solved :D var $j = jQuery; function testClick(){ alert('Button Clicked'); } $j(document).ready(function() { /*$j('.my-button').click(function(){ alert('Button Clicked'); })*/ })


0

SOLVED: can't figure out the best way to update my question, sorry! Thank you Rarst the link you provided helped me figure this out: add_action('wp_enqueue_scripts', 'watercolor_js_scripts'); function watercolor_js_scripts(){ if (!is_admin()) { wp_register_script('cycle2', get_template_directory_uri() . '/js/cycle2.js', array('jquery'), ...


1

Use wp_register_script & wp_enqueue_script to enqueue the scripts the right way. add_action( 'wp_enqueue_scripts', 'enqueue_my_script' ); function enqueue_my_script() { wp_register_script( 'my-script', get_template_directory_uri() . '/cycle2.js', array( 'jquery' ) ); wp_register_script( 'enq-jquery', ...


1

Your snippet seems mostly ok, except that dependency is a list and should be array('jquery'). Also wp_enqueue_scripts should be use as more appropriate. You can check out Codex documentation for a complete example, see Example of Automatic Dependency Loading.



Top 50 recent answers are included