Best Way to Include Scripts on a Specific Template Page

The following (in your theme’s functions.php) will register your script, and set jQuery as a dependency. So when you enqueue it, jQuery will also be enqueued. function my_scripts_method() { // register your script location, dependencies and version wp_register_script(‘my_custom_script’, get_template_directory_uri() . ‘/js/custom_script.js’, array(‘jquery’), ‘1.0’ ); } add_action(‘wp_enqueue_scripts’, ‘my_scripts_method’); You can then enqueue your script one of … Read more

Most elegant way to enqueue scripts in function.php with foreach loop

You need to enqueue the scripts as well, not only register them. You can, however, just simply enqueue a script without registering it if you are not going to enqueue it conditionally. I would try something like this: (Untested and requires PHP5.4+) add_action( ‘wp_enqueue_scripts’, enqueue_scripts, 11 ); function enqueue_scripts() { /** * Build an array … Read more

How do I load custom scripts and styles for a page?

Yes, you may add conditional tags to the wp_enqueue_scripts action. See the examples below: function load_assets() { wp_enqueue_style( ‘styles’, get_template_directory_uri() . ‘/css/styles.css’); // loads on any ‘page’ post type if( is_page() ){ wp_enqueue_script(‘main-js’, get_template_directory_uri() . ‘/js/main.js’); } // only loads on the page with a slug of ‘home’ if( is_page(‘home’) ){ wp_enqueue_script(‘home-js’, get_template_directory_uri() . ‘/js/home.js’); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)