• Resolved Sapientum

    (@sapientum)


    Hi, I’ve been trying to get your plugin to work in a new theme I’m doing, but I appear to have some issues that might be related to jQuery loading…

    In my functions.php, I load Bootstrap as such:

    if (function_exists('wpbootstrap_scripts_with_jquery')) {
    	function wpbootstrap_scripts_with_jquery() {
    		if (!is_admin()) {
    			wp_register_script( 'bootstrap-js', get_template_directory_uri() . '/bootstrap/js/bootstrap.min.js', array( 'jquery' ), '3.3.1', true );
    			wp_register_style( 'bootstrap-css', get_template_directory_uri() . '/bootstrap/css/bootstrap.min.css', array(), '3.3.1', 'all' );
    
    			wp_enqueue_script('bootstrap-js');
    			wp_enqueue_style('bootstrap-css');
    		}
    	}
    	add_action( 'wp_enqueue_scripts', 'wpbootstrap_scripts_with_jquery' );
    }

    And here’s the excerpts from my header file:

    <?php wp_enqueue_script("jquery"); ?>
    	<?php wp_head(); ?>

    and

    <?php echo do_shortcode('[image-carousel]'); ?>

    The issue that occurs is that the below lines produce an error:

    jQuery(document).ready(function() {
    				jQuery('#cptbc_901').carousel({
    					interval: 5000				});
    			});

    You can see the error in the below screenshot:

    https://www.ads-software.com/plugins/cpt-bootstrap-carousel/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Phil Ewels

    (@tallphil)

    Hi Sapientum,

    I can’t see a screenshot.. Any chance you could paste in the error text?

    Cheers,

    Phil

    Thread Starter Sapientum

    (@sapientum)

    https://prntscr.com/5exp6u

    How about now? (and thanks for the fast reply)

    And for backup, the error code is the same as the headline on this thread:
    Uncaught TypeError: undefined is not a function

    It says, that it occurs on this line:
    jQuery('#cptbc_933').carousel({

    Plugin Author Phil Ewels

    (@tallphil)

    Hmm, this sounds like a jQuery / TWBS javascript import error as you say. What do your <head> includes look like on the rendered page? Are both files being correctly linked to / loaded in the correct order? Does the #cptbc_933 element actually exist?

    remember to wrap the function

    (function($) {
    ..your jquery script here
    })(jQuery);

    this my stop your error

    Plugin Author Phil Ewels

    (@tallphil)

    Thanks chef1974 – a good suggestion! I don’t think that the OP has modified the plugin javascript though, and that uses jQuery all of the way through instead of $ so your wrapper shouldn’t make any difference to the problem (though these things are often worth a try anyway!).

    Phil

    Thread Starter Sapientum

    (@sapientum)

    Okay, so I’ve uploaded the theme in development to my site, so you can see for yourself…

    https://www.lastminutegames.dk/

    It’s my first time using Bootstrap in a WordPress theme, so it might be something with how I’m adding it in my functions.php…
    I’ve added my functions.php and header as rtf on my site, in case you would be interested in taking a look…

    Functions: https://www.lastminutegames.dk/docs/functions.rtf
    Header: https://www.lastminutegames.dk/docs/header.rtf

    Plugin Author Phil Ewels

    (@tallphil)

    Hi Sapientum,

    Looking at your rendered source, it looks like the bootstrap javascript isn’t being included. From functions.rtf my guess would be that it’s because of the line:

    if (function_exists('wpbootstrap_scripts_with_jquery')) {

    The function_exists function is used to make sure that things are defined before you execute them. Here, you’re defining the function after the if statement though. So, when it gets to the if statement the function doesn’t exist yet, and so it’s never defined. If you either get rid of this if block or make it if (!function_exists I think you should be ok..

    Let me know if that does the trick!

    Phil

    Thread Starter Sapientum

    (@sapientum)

    Thanks a lot, Phil! That certainly did the trick!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Uncaught TypeError: undefined is not a function’ is closed to new replies.