• I am trying to enqueue some files. I have seen many ways to do it and none are working. Can someone tell me how to load a file from my theme folder?

    I have this on my page:
    <script>
    $( document ).ready( wpb_adding_scripts );
    
    $( window ).load( wpb_adding_scripts );
    </script>
    
    In my functions file I have:
    function wpb_adding_scripts() {
    
    wp_register_script('thickbox', get_stylesheet_directory_uri().'/_js/thickbox.js',array( 'jquery'));
    wp_register_script('jqFancyTransitions', get_stylesheet_directory_uri(__FILE__ ) . '/_js/jqFancyTransitions.1.8.min.js', array('jquery'),'1.8', true);
    wp_register_script('functions',  get_stylesheet_directory_uri(). '/_js/functions.js', array('jquery'),'1.8', true) ;
    }
    
    add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );

Viewing 4 replies - 16 through 19 (of 19 total)
  • This might be just a copy-and-paste error, but I noticed that you’ve registered the scripts, but you’ve never actually enqueued them:

    function wpb_adding_scripts() {
    wp_enqueue_style( 'style-name', get_stylesheet_uri() );//works
    wp_register_script('thickbox', get_template_directory_uri() .'/_js/thickbox.js',  array( ), 3.1, false);
    wp_register_script('jqFancyTransitions', get_template_directory_uri().'/_js/jqFancyTransitions.1.8.min.js',  array(), 1.8, false);
    wp_register_script('functions', get_template_directory_uri().'/_js/functions.js', array( ), 1.1, false);
    wp_enqueue_script( 'thickbox' );
    wp_enqueue_script( 'jqFancyTransitions' );
    wp_enqueue_script( 'functions' );
    }
    add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );
    Thread Starter Bloke

    (@bloke)

    This is how I always do it
    add_action( ‘wp_enqueue_scripts’, ‘wpb_adding_scripts’ );

    That’s the correct code to run the function. Do you call wp_enqueue_script() to output the scripts to the page, like in the code I posted?

    Thread Starter Bloke

    (@bloke)

    Oh I missed that. I put wp_enqueue_media (); I tried inside the function and outside it. I will try tomorrow.

Viewing 4 replies - 16 through 19 (of 19 total)

The topic ‘Enqueue files from theme’ is closed to new replies.