What is the preferred way to add custom javascript files to the site?

Use wp_enqueue_script() in your theme The basic answer is to use wp_enqueue_script() in an wp_enqueue_scripts hook for front end admin_enqueue_scripts for admin. It might look something like this (which assumes you are calling from your theme’s functions.php file; note how I reference the stylesheet directory): <?php add_action( ‘wp_enqueue_scripts’, ‘mysite_enqueue’ ); function mysite_enqueue() { $ss_url = … Read more

Between functions.php (theme), widgets, and plugins, which is loaded first?

The plugins are loaded right before theme (yes, I’ve been looking for excuse to use this): However it is wrong to think about either as point of code execution. For most cases everything should be hooked and executed no earlier than init hook. According to Codex widget registration with register_widget() should be hooked to widget_init. … Read more

How to define and link full path to css located at a random folder on header.php

You should look into wp_enqueue_script() and wp_enque_style(), they’ll handle the assembly and placement of the script/style tag, and the dependancy order – inside of your header (via wp_head()) or footer if you like to load your assets at the bottom of your page. So, for your example, something like add_action( “wp_enqueue_scripts”, function(){ wp_enqueue_style( ‘mythemelightbox’, get_template_directory_uri().’/lightbox2-master/lightbox2-master/src/css/lightbox.css’, … Read more

Where to put my code: plugin or functions.php?

I would start with this question: Is the functionality related to presentation of content, or with generation/management of content, or of the site, or of the user identity? If the functionality is not related specifically to presentation of content, then it is squarely within Plugin Territory. This list is long: Modifying core WP filters (wp_head … Read more